2022-11-11 10:20:33 +02:00
|
|
|
// @ts-expect-error
|
2021-11-29 18:21:29 -06:00
|
|
|
import { getJitsiMeetTransport } from '../../../modules/transport';
|
2019-06-28 15:22:43 -07:00
|
|
|
import {
|
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
|
CONFERENCE_JOINED,
|
2022-11-15 16:54:24 +01:00
|
|
|
DATA_CHANNEL_CLOSED,
|
2021-09-30 11:57:17 +02:00
|
|
|
DATA_CHANNEL_OPENED,
|
2019-06-28 15:22:43 -07:00
|
|
|
KICKED_OUT
|
2022-11-11 10:20:33 +02:00
|
|
|
} from '../base/conference/actionTypes';
|
|
|
|
|
import { SET_CONFIG } from '../base/config/actionTypes';
|
2022-11-01 13:36:32 +01:00
|
|
|
import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices/actionTypes';
|
2019-06-08 10:35:11 -07:00
|
|
|
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
|
2019-06-25 17:58:38 -07:00
|
|
|
import {
|
2019-08-09 13:39:33 +05:30
|
|
|
DOMINANT_SPEAKER_CHANGED,
|
2022-09-27 10:10:28 +03:00
|
|
|
PARTICIPANT_JOINED,
|
2019-06-28 15:22:43 -07:00
|
|
|
PARTICIPANT_KICKED,
|
2019-07-11 12:44:27 -07:00
|
|
|
PARTICIPANT_LEFT,
|
2020-05-05 10:03:54 -04:00
|
|
|
PARTICIPANT_ROLE_CHANGED,
|
2022-11-11 10:20:33 +02:00
|
|
|
SET_LOADABLE_AVATAR_URL
|
|
|
|
|
} from '../base/participants/actionTypes';
|
|
|
|
|
import {
|
2022-09-27 10:10:28 +03:00
|
|
|
getDominantSpeakerParticipant,
|
2019-06-26 16:08:23 +02:00
|
|
|
getLocalParticipant,
|
2024-07-31 13:47:16 +02:00
|
|
|
getParticipantById,
|
|
|
|
|
getParticipantDisplayName
|
2022-11-11 10:20:33 +02: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';
|
2024-12-06 12:28:29 -06:00
|
|
|
import { iAmVisitor } from '../visitors/functions';
|
2019-05-29 14:17:07 -07:00
|
|
|
|
2020-06-04 16:09:13 +02:00
|
|
|
import './subscriber';
|
|
|
|
|
|
2019-05-29 14:17:07 -07:00
|
|
|
/**
|
|
|
|
|
* The middleware of the feature {@code external-api}.
|
|
|
|
|
*
|
|
|
|
|
* @returns {Function}
|
|
|
|
|
*/
|
2019-06-25 17:58:38 -07:00
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2019-06-26 16:08:23 +02:00
|
|
|
// We need to do these before executing the rest of the middelware chain
|
|
|
|
|
switch (action.type) {
|
2022-09-08 16:14:00 -05: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 16:08:23 +02:00
|
|
|
case SET_LOADABLE_AVATAR_URL: {
|
|
|
|
|
const { id, loadableAvatarUrl } = action.participant;
|
|
|
|
|
const participant = getParticipantById(
|
|
|
|
|
store.getState(),
|
|
|
|
|
id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const result = next(action);
|
|
|
|
|
|
2019-07-03 17:39:39 +02: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 16:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 17:58:38 -07:00
|
|
|
const result = next(action);
|
|
|
|
|
|
2019-06-26 16:08:23 +02:00
|
|
|
// These should happen after the rest of the middleware chain ran
|
2019-05-29 14:17:07 -07:00
|
|
|
switch (action.type) {
|
2019-06-08 10:35:11 -07:00
|
|
|
case CONFERENCE_FAILED: {
|
|
|
|
|
if (action.conference
|
|
|
|
|
&& action.error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
|
|
|
|
|
APP.API.notifyOnPasswordRequired();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 17:58:38 -07:00
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
|
const state = store.getState();
|
2021-11-26 17:39:34 +02:00
|
|
|
const { defaultLocalDisplayName } = state['features/base/config'];
|
2022-02-02 13:28:07 +02:00
|
|
|
const { room } = state['features/base/conference'];
|
2022-11-11 10:20:33 +02:00
|
|
|
const { loadableAvatarUrl, name, id, email } = getLocalParticipant(state) ?? {};
|
|
|
|
|
const breakoutRoom = APP.conference.roomName.toString() !== room?.toLowerCase();
|
2019-06-25 17:58:38 -07:00
|
|
|
|
2021-12-15 15:50:03 -06: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-25 17:58:38 -07:00
|
|
|
APP.API.notifyConferenceJoined(
|
2021-12-15 15:50:03 -06:00
|
|
|
APP.conference.roomName,
|
2019-06-25 17:58:38 -07:00
|
|
|
id,
|
|
|
|
|
{
|
|
|
|
|
displayName: name,
|
|
|
|
|
formattedDisplayName: appendSuffix(
|
2022-11-11 10:20:33 +02:00
|
|
|
name ?? '',
|
2021-11-26 17:39:34 +02:00
|
|
|
defaultLocalDisplayName
|
2019-06-25 17:58:38 -07:00
|
|
|
),
|
2022-02-02 13:28:07 +02:00
|
|
|
avatarURL: loadableAvatarUrl,
|
2022-09-14 13:48:00 +03:00
|
|
|
breakoutRoom,
|
2024-12-06 12:28:29 -06:00
|
|
|
email,
|
|
|
|
|
visitor: iAmVisitor(state)
|
2019-06-25 17:58:38 -07:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 16:54:24 +01:00
|
|
|
case DATA_CHANNEL_CLOSED:
|
|
|
|
|
APP.API.notifyDataChannelClosed(action.code, action.reason);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-09-30 11:57:17 +02:00
|
|
|
case DATA_CHANNEL_OPENED:
|
|
|
|
|
APP.API.notifyDataChannelOpened();
|
|
|
|
|
break;
|
|
|
|
|
|
2024-07-31 13:47:16 +02:00
|
|
|
case KICKED_OUT: {
|
|
|
|
|
const state = store.getState();
|
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
|
|
if (!localParticipant) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-22 12:22:44 -06:00
|
|
|
const actor = action.participant;
|
2024-07-31 13:47:16 +02:00
|
|
|
|
2019-06-28 15:22:43 -07:00
|
|
|
APP.API.notifyKickedOut(
|
|
|
|
|
{
|
2024-07-31 13:47:16 +02:00
|
|
|
id: localParticipant.id,
|
|
|
|
|
name: getParticipantDisplayName(state, localParticipant.id),
|
2019-06-28 15:22:43 -07:00
|
|
|
local: true
|
|
|
|
|
},
|
2024-07-31 13:47:16 +02:00
|
|
|
{
|
2024-12-12 19:03:26 +02:00
|
|
|
id: actor?.getId(),
|
|
|
|
|
name: actor?.getDisplayName()
|
2024-07-31 13:47:16 +02:00
|
|
|
}
|
2019-06-28 15:22:43 -07:00
|
|
|
);
|
|
|
|
|
break;
|
2024-07-31 13:47:16 +02:00
|
|
|
}
|
2019-06-28 15:22:43 -07:00
|
|
|
|
2019-05-29 14:17:07 -07:00
|
|
|
case NOTIFY_CAMERA_ERROR:
|
|
|
|
|
if (action.error) {
|
|
|
|
|
APP.API.notifyOnCameraError(
|
2022-11-11 10:20:33 +02:00
|
|
|
action.error.name, action.error.message);
|
2019-05-29 14:17:07 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NOTIFY_MIC_ERROR:
|
|
|
|
|
if (action.error) {
|
|
|
|
|
APP.API.notifyOnMicError(action.error.name, action.error.message);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-23 07:25:07 -07:00
|
|
|
|
2024-07-31 13:47:16 +02:00
|
|
|
case PARTICIPANT_KICKED: {
|
|
|
|
|
const state = store.getState();
|
|
|
|
|
const kickedParticipant = getParticipantById(state, action.kicked);
|
|
|
|
|
const kickerParticipant = getParticipantById(state, action.kicker);
|
|
|
|
|
|
|
|
|
|
if (!kickerParticipant || !kickedParticipant) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 15:22:43 -07:00
|
|
|
APP.API.notifyKickedOut(
|
|
|
|
|
{
|
2024-07-31 13:47:16 +02:00
|
|
|
id: kickedParticipant.id,
|
|
|
|
|
local: kickedParticipant.local,
|
|
|
|
|
name: getParticipantDisplayName(state, kickedParticipant.id)
|
2019-06-28 15:22:43 -07:00
|
|
|
},
|
2024-07-31 13:47:16 +02:00
|
|
|
{
|
|
|
|
|
id: kickerParticipant.id,
|
|
|
|
|
local: kickerParticipant.local,
|
|
|
|
|
name: getParticipantDisplayName(state, kickerParticipant.id)
|
|
|
|
|
});
|
2019-06-28 15:22:43 -07:00
|
|
|
break;
|
2024-07-31 13:47:16 +02:00
|
|
|
}
|
2019-06-28 15:22:43 -07:00
|
|
|
|
2022-09-06 09:51:38 +03:00
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
|
const { participant } = action;
|
2022-10-06 14:12:57 +03:00
|
|
|
const { fakeParticipant } = participant;
|
2022-09-06 09:51:38 +03:00
|
|
|
|
2022-10-06 14:12:57 +03:00
|
|
|
// Skip sending participant left event for fake participants.
|
|
|
|
|
if (fakeParticipant) {
|
2022-09-06 09:51:38 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 12:44:27 -07:00
|
|
|
APP.API.notifyUserLeft(action.participant.id);
|
|
|
|
|
break;
|
2022-09-06 09:51:38 +03:00
|
|
|
}
|
2019-07-11 12:44:27 -07:00
|
|
|
case PARTICIPANT_JOINED: {
|
2021-11-26 17:39:34 +02:00
|
|
|
const state = store.getState();
|
|
|
|
|
const { defaultRemoteDisplayName } = state['features/base/config'];
|
2019-07-11 12:44:27 -07:00
|
|
|
const { participant } = action;
|
2022-10-06 14:12:57 +03:00
|
|
|
const { fakeParticipant, id, local, name } = participant;
|
2019-07-11 12:44:27 -07:00
|
|
|
|
|
|
|
|
// The version of external api outside of middleware did not emit
|
|
|
|
|
// the local participant being created.
|
|
|
|
|
if (!local) {
|
2022-10-06 14:12:57 +03:00
|
|
|
// Skip sending participant joined event for fake participants.
|
|
|
|
|
if (fakeParticipant) {
|
2022-09-06 09:51:38 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 12:44:27 -07:00
|
|
|
APP.API.notifyUserJoined(id, {
|
|
|
|
|
displayName: name,
|
|
|
|
|
formattedDisplayName: appendSuffix(
|
2021-11-26 17:39:34 +02:00
|
|
|
name || defaultRemoteDisplayName)
|
2019-07-11 12:44:27 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 10:03:54 -04:00
|
|
|
case PARTICIPANT_ROLE_CHANGED:
|
|
|
|
|
APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-11-29 18:21:29 -06: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 07:46:50 -07:00
|
|
|
case SET_FILMSTRIP_VISIBLE:
|
|
|
|
|
APP.API.notifyFilmstripDisplayChanged(action.visible);
|
|
|
|
|
break;
|
|
|
|
|
|
2019-07-31 10:59:22 -07:00
|
|
|
case SUBMIT_FEEDBACK_ERROR:
|
|
|
|
|
APP.API.notifyFeedbackSubmitted(action.error || 'Unknown error');
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SUBMIT_FEEDBACK_SUCCESS:
|
2019-06-23 07:25:07 -07:00
|
|
|
APP.API.notifyFeedbackSubmitted();
|
|
|
|
|
break;
|
2019-05-29 14:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-25 17:58:38 -07:00
|
|
|
return result;
|
2019-05-29 14:17:07 -07:00
|
|
|
});
|
2019-07-03 17:39:39 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the absolute URL of the default avatar.
|
|
|
|
|
*
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
function _getDefaultAvatarUrl() {
|
|
|
|
|
return new URL('images/avatar.png', getBaseUrl()).href;
|
|
|
|
|
}
|