2019-05-29 21:17:07 +00:00
|
|
|
// @flow
|
|
|
|
|
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
|
|
|
|
} from '../base/conference';
|
2021-11-30 00:21:29 +00:00
|
|
|
import { SET_CONFIG } from '../base/config';
|
2019-05-29 21:17:07 +00:00
|
|
|
import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices';
|
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,
|
2019-06-28 22:22:43 +00:00
|
|
|
PARTICIPANT_KICKED,
|
2019-07-11 19:44:27 +00:00
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
PARTICIPANT_JOINED,
|
2020-05-05 14:03:54 +00:00
|
|
|
PARTICIPANT_ROLE_CHANGED,
|
2019-06-26 14:08:23 +00:00
|
|
|
SET_LOADABLE_AVATAR_URL,
|
|
|
|
getLocalParticipant,
|
2022-09-08 21:14:00 +00:00
|
|
|
getParticipantById,
|
|
|
|
getDominantSpeakerParticipant
|
2019-06-26 00:58:38 +00:00
|
|
|
} from '../base/participants';
|
2019-05-29 21:17:07 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2019-07-03 15:39:39 +00:00
|
|
|
import { getBaseUrl } from '../base/util';
|
2019-06-26 00:58:38 +00:00
|
|
|
import { appendSuffix } from '../display-name';
|
2019-07-31 17:59:22 +00:00
|
|
|
import { SUBMIT_FEEDBACK_ERROR, SUBMIT_FEEDBACK_SUCCESS } from '../feedback';
|
2019-06-23 14:46:50 +00:00
|
|
|
import { SET_FILMSTRIP_VISIBLE } from '../filmstrip';
|
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
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09-14 10:48:00 +00:00
|
|
|
const { loadableAvatarUrl, name, id, email } = getLocalParticipant(state);
|
2022-02-02 11:28:07 +00:00
|
|
|
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(
|
|
|
|
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(
|
|
|
|
{
|
|
|
|
id: getLocalParticipant(store.getState()).id,
|
|
|
|
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(
|
|
|
|
action.error.name, action.error.message);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
const { isFakeParticipant, isVirtualScreenshareParticipant } = participant;
|
|
|
|
|
|
|
|
// Skip sending participant left event for fake or virtual screenshare participants.
|
|
|
|
if (isFakeParticipant || isVirtualScreenshareParticipant) {
|
|
|
|
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-09-06 06:51:38 +00:00
|
|
|
const { id, isFakeParticipant, isVirtualScreenshareParticipant, 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-09-06 06:51:38 +00:00
|
|
|
// Skip sending participant joined event for fake or virtual screenshare participants.
|
|
|
|
if (isFakeParticipant || isVirtualScreenshareParticipant) {
|
|
|
|
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;
|
|
|
|
}
|