2022-11-11 08:20:33 +00:00
|
|
|
// @ts-expect-error
|
2021-11-30 00:21:29 +00:00
|
|
|
import { getJitsiMeetTransport } from '../../../modules/transport';
|
2019-06-28 22:22:43 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_JOINED,
|
2021-09-30 09:57:17 +00:00
|
|
|
DATA_CHANNEL_OPENED,
|
2019-06-28 22:22:43 +00:00
|
|
|
KICKED_OUT
|
2022-11-11 08:20:33 +00:00
|
|
|
} from '../base/conference/actionTypes';
|
|
|
|
import { SET_CONFIG } from '../base/config/actionTypes';
|
2022-11-01 12:36:32 +00:00
|
|
|
import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices/actionTypes';
|
2019-06-08 17:35:11 +00:00
|
|
|
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
|
2019-06-26 00:58:38 +00:00
|
|
|
import {
|
2019-08-09 08:09:33 +00:00
|
|
|
DOMINANT_SPEAKER_CHANGED,
|
2022-09-27 07:10:28 +00:00
|
|
|
PARTICIPANT_JOINED,
|
2019-06-28 22:22:43 +00:00
|
|
|
PARTICIPANT_KICKED,
|
2019-07-11 19:44:27 +00:00
|
|
|
PARTICIPANT_LEFT,
|
2020-05-05 14:03:54 +00:00
|
|
|
PARTICIPANT_ROLE_CHANGED,
|
2022-11-11 08:20:33 +00:00
|
|
|
SET_LOADABLE_AVATAR_URL
|
|
|
|
} from '../base/participants/actionTypes';
|
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
getDominantSpeakerParticipant,
|
2019-06-26 14:08:23 +00:00
|
|
|
getLocalParticipant,
|
2022-09-27 07:10:28 +00:00
|
|
|
getParticipantById
|
2022-11-11 08:20:33 +00:00
|
|
|
} from '../base/participants/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import { getBaseUrl } from '../base/util/helpers';
|
|
|
|
import { appendSuffix } from '../display-name/functions';
|
|
|
|
import { SUBMIT_FEEDBACK_ERROR, SUBMIT_FEEDBACK_SUCCESS } from '../feedback/actionTypes';
|
|
|
|
import { SET_FILMSTRIP_VISIBLE } from '../filmstrip/actionTypes';
|
2019-05-29 21:17:07 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import './subscriber';
|
|
|
|
|
2019-05-29 21:17:07 +00:00
|
|
|
/**
|
|
|
|
* The middleware of the feature {@code external-api}.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2019-06-26 00:58:38 +00:00
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2019-06-26 14:08:23 +00:00
|
|
|
// We need to do these before executing the rest of the middelware chain
|
|
|
|
switch (action.type) {
|
2022-09-08 21:14:00 +00:00
|
|
|
case DOMINANT_SPEAKER_CHANGED: {
|
|
|
|
const dominantSpeaker = getDominantSpeakerParticipant(store.getState());
|
|
|
|
|
|
|
|
if (dominantSpeaker?.id !== action.participant.id) {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
APP.API.notifyDominantSpeakerChanged(action.participant.id);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-06-26 14:08:23 +00:00
|
|
|
case SET_LOADABLE_AVATAR_URL: {
|
|
|
|
const { id, loadableAvatarUrl } = action.participant;
|
|
|
|
const participant = getParticipantById(
|
|
|
|
store.getState(),
|
|
|
|
id
|
|
|
|
);
|
|
|
|
|
|
|
|
const result = next(action);
|
|
|
|
|
2019-07-03 15:39:39 +00:00
|
|
|
if (participant) {
|
|
|
|
if (loadableAvatarUrl) {
|
|
|
|
participant.loadableAvatarUrl !== loadableAvatarUrl && APP.API.notifyAvatarChanged(
|
|
|
|
id,
|
|
|
|
loadableAvatarUrl
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// There is no loadable explicit URL. In this case the Avatar component would
|
|
|
|
// decide to render initials or the default avatar, but the external API needs
|
|
|
|
// a URL when it needs to be rendered, so if there is no initials, we return the default
|
|
|
|
// Avatar URL as if it was a usual avatar URL. If there are (or may be) initials
|
|
|
|
// we send undefined to signal the api user that it's not an URL that needs to be rendered.
|
|
|
|
//
|
|
|
|
// NOTE: we may implement a special URL format later to signal that the avatar is based
|
|
|
|
// on initials, that API consumers can handle as they want, e.g. initials://jm
|
|
|
|
APP.API.notifyAvatarChanged(
|
|
|
|
id,
|
|
|
|
participant.name ? undefined : _getDefaultAvatarUrl()
|
|
|
|
);
|
|
|
|
}
|
2019-06-26 14:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 00:58:38 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2019-06-26 14:08:23 +00:00
|
|
|
// These should happen after the rest of the middleware chain ran
|
2019-05-29 21:17:07 +00:00
|
|
|
switch (action.type) {
|
2019-06-08 17:35:11 +00:00
|
|
|
case CONFERENCE_FAILED: {
|
|
|
|
if (action.conference
|
|
|
|
&& action.error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
|
|
|
|
APP.API.notifyOnPasswordRequired();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-26 00:58:38 +00:00
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
const state = store.getState();
|
2021-11-26 15:39:34 +00:00
|
|
|
const { defaultLocalDisplayName } = state['features/base/config'];
|
2022-02-02 11:28:07 +00:00
|
|
|
const { room } = state['features/base/conference'];
|
2022-11-11 08:20:33 +00:00
|
|
|
const { loadableAvatarUrl, name, id, email } = getLocalParticipant(state) ?? {};
|
|
|
|
const breakoutRoom = APP.conference.roomName.toString() !== room?.toLowerCase();
|
2019-06-26 00:58:38 +00:00
|
|
|
|
2021-12-15 21:50:03 +00:00
|
|
|
// we use APP.conference.roomName as we do not update state['features/base/conference'].room when
|
|
|
|
// moving between rooms in case of breakout rooms and it stays always with the name of the main room
|
2019-06-26 00:58:38 +00:00
|
|
|
APP.API.notifyConferenceJoined(
|
2021-12-15 21:50:03 +00:00
|
|
|
APP.conference.roomName,
|
2019-06-26 00:58:38 +00:00
|
|
|
id,
|
|
|
|
{
|
|
|
|
displayName: name,
|
|
|
|
formattedDisplayName: appendSuffix(
|
2022-11-11 08:20:33 +00:00
|
|
|
name ?? '',
|
2021-11-26 15:39:34 +00:00
|
|
|
defaultLocalDisplayName
|
2019-06-26 00:58:38 +00:00
|
|
|
),
|
2022-02-02 11:28:07 +00:00
|
|
|
avatarURL: loadableAvatarUrl,
|
2022-09-14 10:48:00 +00:00
|
|
|
breakoutRoom,
|
|
|
|
email
|
2019-06-26 00:58:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-30 09:57:17 +00:00
|
|
|
case DATA_CHANNEL_OPENED:
|
|
|
|
APP.API.notifyDataChannelOpened();
|
|
|
|
break;
|
|
|
|
|
2019-06-28 22:22:43 +00:00
|
|
|
case KICKED_OUT:
|
|
|
|
APP.API.notifyKickedOut(
|
|
|
|
{
|
2022-11-11 08:20:33 +00:00
|
|
|
id: getLocalParticipant(store.getState())?.id,
|
2019-06-28 22:22:43 +00:00
|
|
|
local: true
|
|
|
|
},
|
2021-06-11 08:58:45 +00:00
|
|
|
{ id: action.participant ? action.participant.getId() : undefined }
|
2019-06-28 22:22:43 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2019-05-29 21:17:07 +00:00
|
|
|
case NOTIFY_CAMERA_ERROR:
|
|
|
|
if (action.error) {
|
|
|
|
APP.API.notifyOnCameraError(
|
2022-11-11 08:20:33 +00:00
|
|
|
action.error.name, action.error.message);
|
2019-05-29 21:17:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOTIFY_MIC_ERROR:
|
|
|
|
if (action.error) {
|
|
|
|
APP.API.notifyOnMicError(action.error.name, action.error.message);
|
|
|
|
}
|
|
|
|
break;
|
2019-06-23 14:25:07 +00:00
|
|
|
|
2019-06-28 22:22:43 +00:00
|
|
|
case PARTICIPANT_KICKED:
|
|
|
|
APP.API.notifyKickedOut(
|
|
|
|
{
|
|
|
|
id: action.kicked,
|
|
|
|
local: false
|
|
|
|
},
|
|
|
|
{ id: action.kicker });
|
|
|
|
break;
|
|
|
|
|
2022-09-06 06:51:38 +00:00
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
const { participant } = action;
|
2022-10-06 11:12:57 +00:00
|
|
|
const { fakeParticipant } = participant;
|
2022-09-06 06:51:38 +00:00
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
// Skip sending participant left event for fake participants.
|
|
|
|
if (fakeParticipant) {
|
2022-09-06 06:51:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:44:27 +00:00
|
|
|
APP.API.notifyUserLeft(action.participant.id);
|
|
|
|
break;
|
2022-09-06 06:51:38 +00:00
|
|
|
}
|
2019-07-11 19:44:27 +00:00
|
|
|
case PARTICIPANT_JOINED: {
|
2021-11-26 15:39:34 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const { defaultRemoteDisplayName } = state['features/base/config'];
|
2019-07-11 19:44:27 +00:00
|
|
|
const { participant } = action;
|
2022-10-06 11:12:57 +00:00
|
|
|
const { fakeParticipant, id, local, name } = participant;
|
2019-07-11 19:44:27 +00:00
|
|
|
|
|
|
|
// The version of external api outside of middleware did not emit
|
|
|
|
// the local participant being created.
|
|
|
|
if (!local) {
|
2022-10-06 11:12:57 +00:00
|
|
|
// Skip sending participant joined event for fake participants.
|
|
|
|
if (fakeParticipant) {
|
2022-09-06 06:51:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:44:27 +00:00
|
|
|
APP.API.notifyUserJoined(id, {
|
|
|
|
displayName: name,
|
|
|
|
formattedDisplayName: appendSuffix(
|
2021-11-26 15:39:34 +00:00
|
|
|
name || defaultRemoteDisplayName)
|
2019-07-11 19:44:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-05 14:03:54 +00:00
|
|
|
case PARTICIPANT_ROLE_CHANGED:
|
|
|
|
APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role);
|
|
|
|
break;
|
|
|
|
|
2021-11-30 00:21:29 +00:00
|
|
|
case SET_CONFIG: {
|
|
|
|
const state = store.getState();
|
|
|
|
const { disableBeforeUnloadHandlers = false } = state['features/base/config'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disposing the API when the user closes the page.
|
|
|
|
*/
|
|
|
|
window.addEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', () => {
|
|
|
|
APP.API.notifyConferenceLeft(APP.conference.roomName);
|
|
|
|
APP.API.dispose();
|
|
|
|
getJitsiMeetTransport().dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-23 14:46:50 +00:00
|
|
|
case SET_FILMSTRIP_VISIBLE:
|
|
|
|
APP.API.notifyFilmstripDisplayChanged(action.visible);
|
|
|
|
break;
|
|
|
|
|
2019-07-31 17:59:22 +00:00
|
|
|
case SUBMIT_FEEDBACK_ERROR:
|
|
|
|
APP.API.notifyFeedbackSubmitted(action.error || 'Unknown error');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SUBMIT_FEEDBACK_SUCCESS:
|
2019-06-23 14:25:07 +00:00
|
|
|
APP.API.notifyFeedbackSubmitted();
|
|
|
|
break;
|
2019-05-29 21:17:07 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 00:58:38 +00:00
|
|
|
return result;
|
2019-05-29 21:17:07 +00:00
|
|
|
});
|
2019-07-03 15:39:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the absolute URL of the default avatar.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function _getDefaultAvatarUrl() {
|
|
|
|
return new URL('images/avatar.png', getBaseUrl()).href;
|
|
|
|
}
|