This commit is contained in:
381
react/features/base/conference/actionTypes.ts
Normal file
381
react/features/base/conference/actionTypes.ts
Normal file
@@ -0,0 +1,381 @@
|
||||
/**
|
||||
* The type of (redux) action which signals that server authentication has
|
||||
* becoming available or unavailable or logged in user has changed.
|
||||
*
|
||||
* {
|
||||
* type: AUTH_STATUS_CHANGED,
|
||||
* authEnabled: boolean,
|
||||
* authLogin: string
|
||||
* }
|
||||
*/
|
||||
export const AUTH_STATUS_CHANGED = 'AUTH_STATUS_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference failed.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_FAILED,
|
||||
* conference: JitsiConference,
|
||||
* error: Error
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_FAILED = 'CONFERENCE_FAILED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference was
|
||||
* joined.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_JOINED,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_JOINED = 'CONFERENCE_JOINED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference joining is in progress.
|
||||
* A CONFERENCE_JOINED is guaranteed to follow.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_JOIN_IN_PROGRESS,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_JOIN_IN_PROGRESS = 'CONFERENCE_JOIN_IN_PROGRESS';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference was left.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_LEFT,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_LEFT = 'CONFERENCE_LEFT';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the conference is out of focus.
|
||||
* For example, if the user navigates to the Chat screen.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_BLURRED,
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_BLURRED = 'CONFERENCE_BLURRED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the conference is in focus.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_FOCUSED,
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_FOCUSED = 'CONFERENCE_FOCUSED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action, which indicates conference local subject changes.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_LOCAL_SUBJECT_CHANGED
|
||||
* subject: string
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_LOCAL_SUBJECT_CHANGED = 'CONFERENCE_LOCAL_SUBJECT_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action, which indicates conference properties change.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_PROPERTIES_CHANGED
|
||||
* properties: {
|
||||
* audio-recording-enabled: boolean,
|
||||
* visitor-count: number
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_PROPERTIES_CHANGED = 'CONFERENCE_PROPERTIES_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action, which indicates conference subject changes.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_SUBJECT_CHANGED
|
||||
* subject: string
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_SUBJECT_CHANGED = 'CONFERENCE_SUBJECT_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action, which indicates conference UTC timestamp changes.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_TIMESTAMP_CHANGED
|
||||
* timestamp: number
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_TIMESTAMP_CHANGED = 'CONFERENCE_TIMESTAMP_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that an uuid for a conference has been set.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_UNIQUE_ID_SET,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_UNIQUE_ID_SET = 'CONFERENCE_UNIQUE_ID_SET';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the end-to-end RTT against a specific remote participant has changed.
|
||||
*
|
||||
* {
|
||||
* type: E2E_RTT_CHANGED,
|
||||
* e2eRtt: {
|
||||
* rtt: number,
|
||||
* participant: Object,
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export const E2E_RTT_CHANGED = 'E2E_RTT_CHANGED'
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a conference will be initialized.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_WILL_INIT
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_WILL_INIT = 'CONFERENCE_WILL_INIT';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference will be
|
||||
* joined.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_WILL_JOIN,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_WILL_JOIN = 'CONFERENCE_WILL_JOIN';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a specific conference will be
|
||||
* left.
|
||||
*
|
||||
* {
|
||||
* type: CONFERENCE_WILL_LEAVE,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const CONFERENCE_WILL_LEAVE = 'CONFERENCE_WILL_LEAVE';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the data channel with the
|
||||
* bridge has been established.
|
||||
*
|
||||
* {
|
||||
* type: DATA_CHANNEL_OPENED
|
||||
* }
|
||||
*/
|
||||
export const DATA_CHANNEL_OPENED = 'DATA_CHANNEL_OPENED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the data channel with the
|
||||
* bridge has been closed.
|
||||
*
|
||||
* {
|
||||
* type: DATA_CHANNEL_CLOSED,
|
||||
* code: number,
|
||||
* reason: string
|
||||
* }
|
||||
*/
|
||||
export const DATA_CHANNEL_CLOSED = 'DATA_CHANNEL_CLOSED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which indicates that an endpoint message
|
||||
* sent by another participant to the data channel is received.
|
||||
*
|
||||
* {
|
||||
* type: ENDPOINT_MESSAGE_RECEIVED,
|
||||
* participant: Object,
|
||||
* data: Object
|
||||
* }
|
||||
*/
|
||||
export const ENDPOINT_MESSAGE_RECEIVED = 'ENDPOINT_MESSAGE_RECEIVED';
|
||||
|
||||
/**
|
||||
* The type of action which signals that the user has been kicked out from
|
||||
* the conference.
|
||||
*
|
||||
* {
|
||||
* type: KICKED_OUT,
|
||||
* conference: JitsiConference
|
||||
* }
|
||||
*/
|
||||
export const KICKED_OUT = 'KICKED_OUT';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that the lock state of a specific
|
||||
* {@code JitsiConference} changed.
|
||||
*
|
||||
* {
|
||||
* type: LOCK_STATE_CHANGED,
|
||||
* conference: JitsiConference,
|
||||
* locked: boolean
|
||||
* }
|
||||
*/
|
||||
export const LOCK_STATE_CHANGED = 'LOCK_STATE_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that a system (non-participant) message has been received.
|
||||
*
|
||||
* {
|
||||
* type: NON_PARTICIPANT_MESSAGE_RECEIVED,
|
||||
* id: String,
|
||||
* json: Object
|
||||
* }
|
||||
*/
|
||||
export const NON_PARTICIPANT_MESSAGE_RECEIVED = 'NON_PARTICIPANT_MESSAGE_RECEIVED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which sets the peer2peer flag for the current
|
||||
* conference.
|
||||
*
|
||||
* {
|
||||
* type: P2P_STATUS_CHANGED,
|
||||
* p2p: boolean
|
||||
* }
|
||||
*/
|
||||
export const P2P_STATUS_CHANGED = 'P2P_STATUS_CHANGED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals to play specified touch tones.
|
||||
*
|
||||
* {
|
||||
* type: SEND_TONES,
|
||||
* tones: string,
|
||||
* duration: number,
|
||||
* pause: number
|
||||
* }
|
||||
*/
|
||||
export const SEND_TONES = 'SEND_TONES';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updates the current known status of the
|
||||
* Follow Me feature.
|
||||
*
|
||||
* {
|
||||
* type: SET_FOLLOW_ME,
|
||||
* enabled: boolean
|
||||
* }
|
||||
*/
|
||||
export const SET_FOLLOW_ME = 'SET_FOLLOW_ME';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updates the current known status of the
|
||||
* Follow Me feature that is used only by the recorder.
|
||||
*
|
||||
* {
|
||||
* type: SET_FOLLOW_ME_RECORDER,
|
||||
* enabled: boolean
|
||||
* }
|
||||
*/
|
||||
export const SET_FOLLOW_ME_RECORDER = 'SET_FOLLOW_ME_RECORDER';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which sets the obfuscated room name.
|
||||
*
|
||||
* {
|
||||
* type: SET_OBFUSCATED_ROOM,
|
||||
* obfuscatedRoom: string
|
||||
* }
|
||||
*/
|
||||
export const SET_OBFUSCATED_ROOM = 'SET_OBFUSCATED_ROOM';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updates the current known status of the
|
||||
* Mute Reactions Sound feature.
|
||||
*
|
||||
* {
|
||||
* type: SET_START_REACTIONS_MUTED,
|
||||
* enabled: boolean
|
||||
* }
|
||||
*/
|
||||
export const SET_START_REACTIONS_MUTED = 'SET_START_REACTIONS_MUTED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which sets the password to join or lock a specific
|
||||
* {@code JitsiConference}.
|
||||
*
|
||||
* {
|
||||
* type: SET_PASSWORD,
|
||||
* conference: JitsiConference,
|
||||
* method: Function
|
||||
* password: string
|
||||
* }
|
||||
*/
|
||||
export const SET_PASSWORD = 'SET_PASSWORD';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals that setting a password on a
|
||||
* {@code JitsiConference} failed (with an error).
|
||||
*
|
||||
* {
|
||||
* type: SET_PASSWORD_FAILED,
|
||||
* error: string
|
||||
* }
|
||||
*/
|
||||
export const SET_PASSWORD_FAILED = 'SET_PASSWORD_FAILED';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which signals for pending subject changes.
|
||||
*
|
||||
* {
|
||||
* type: SET_PENDING_SUBJECT_CHANGE,
|
||||
* subject: string
|
||||
* }
|
||||
*/
|
||||
export const SET_PENDING_SUBJECT_CHANGE = 'SET_PENDING_SUBJECT_CHANGE';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which sets the name of the room of the
|
||||
* conference to be joined.
|
||||
*
|
||||
* {
|
||||
* type: SET_ROOM,
|
||||
* room: string
|
||||
* }
|
||||
*/
|
||||
export const SET_ROOM = 'SET_ROOM';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updates the current known status of the
|
||||
* moderator features for starting participants as audio or video muted.
|
||||
*
|
||||
* {
|
||||
* type: SET_START_MUTED_POLICY,
|
||||
* startAudioMutedPolicy: boolean,
|
||||
* startVideoMutedPolicy: boolean
|
||||
* }
|
||||
*/
|
||||
export const SET_START_MUTED_POLICY = 'SET_START_MUTED_POLICY';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updates the assumed bandwidth bps.
|
||||
*
|
||||
* {
|
||||
* type: SET_ASSUMED_BANDWIDTH_BPS,
|
||||
* assumedBandwidthBps: number
|
||||
* }
|
||||
*/
|
||||
export const SET_ASSUMED_BANDWIDTH_BPS = 'SET_ASSUMED_BANDWIDTH_BPS';
|
||||
|
||||
/**
|
||||
* The type of (redux) action which updated the conference metadata.
|
||||
*
|
||||
* {
|
||||
* type: UPDATE_CONFERENCE_METADATA,
|
||||
* metadata: Object
|
||||
* }
|
||||
*/
|
||||
export const UPDATE_CONFERENCE_METADATA = 'UPDATE_CONFERENCE_METADATA';
|
||||
1152
react/features/base/conference/actions.any.ts
Normal file
1152
react/features/base/conference/actions.any.ts
Normal file
File diff suppressed because it is too large
Load Diff
29
react/features/base/conference/actions.native.ts
Normal file
29
react/features/base/conference/actions.native.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { IStore } from '../../app/types';
|
||||
import { setAudioMuted, setVideoMuted } from '../media/actions';
|
||||
import { MEDIA_TYPE, MediaType, VIDEO_MUTISM_AUTHORITY } from '../media/constants';
|
||||
|
||||
export * from './actions.any';
|
||||
|
||||
/**
|
||||
* Starts audio and/or video for the visitor.
|
||||
*
|
||||
* @param {Array<MediaType>} mediaTypes - The media types that need to be started.
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function setupVisitorStartupMedia(mediaTypes: Array<MediaType>) {
|
||||
return (dispatch: IStore['dispatch']) => {
|
||||
if (!mediaTypes || !Array.isArray(mediaTypes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaTypes.forEach(mediaType => {
|
||||
switch (mediaType) {
|
||||
case MEDIA_TYPE.AUDIO:
|
||||
dispatch(setAudioMuted(false, true));
|
||||
break;
|
||||
case MEDIA_TYPE.VIDEO:
|
||||
dispatch(setVideoMuted(false, VIDEO_MUTISM_AUTHORITY.USER, true));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
25
react/features/base/conference/actions.web.ts
Normal file
25
react/features/base/conference/actions.web.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { IStore } from '../../app/types';
|
||||
import { gumPending } from '../media/actions';
|
||||
import { MEDIA_TYPE, MediaType } from '../media/constants';
|
||||
import { IGUMPendingState } from '../media/types';
|
||||
import { createAndAddInitialAVTracks } from '../tracks/actions.web';
|
||||
|
||||
export * from './actions.any';
|
||||
|
||||
/**
|
||||
* Starts audio and/or video for the visitor.
|
||||
*
|
||||
* @param {Array<MediaType>} media - The media types that need to be started.
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function setupVisitorStartupMedia(media: Array<MediaType>) {
|
||||
return (dispatch: IStore['dispatch']) => {
|
||||
// Clear the gum pending state in case we have set it to pending since we are starting the
|
||||
// conference without tracks.
|
||||
dispatch(gumPending([ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ], IGUMPendingState.NONE));
|
||||
|
||||
if (media && Array.isArray(media) && media.length > 0) {
|
||||
dispatch(createAndAddInitialAVTracks(media));
|
||||
}
|
||||
};
|
||||
}
|
||||
47
react/features/base/conference/constants.ts
Normal file
47
react/features/base/conference/constants.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* The command type for updating a participant's avatar URL.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
export const AVATAR_URL_COMMAND = 'avatar-url';
|
||||
|
||||
/**
|
||||
* The command type for updating a participant's email address.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
export const EMAIL_COMMAND = 'email';
|
||||
|
||||
/**
|
||||
* The name of the {@code JitsiConference} property which identifies the URL of
|
||||
* the conference represented by the {@code JitsiConference} instance.
|
||||
*
|
||||
* TODO It was introduced in a moment of desperation. Jitsi Meet SDK for Android
|
||||
* and iOS needs to deliver events from the JavaScript side where they originate
|
||||
* to the Java and Objective-C sides, respectively, where they are to be
|
||||
* handled. The URL of the {@code JitsiConference} was chosen as the identifier
|
||||
* because the Java and Objective-C sides join by URL through their respective
|
||||
* loadURL methods. But features/base/connection's {@code locationURL} is not
|
||||
* guaranteed at the time of this writing to match the {@code JitsiConference}
|
||||
* instance when the events are to be fired. Patching {@code JitsiConference}
|
||||
* from the outside is not cool but it should suffice for now.
|
||||
*/
|
||||
export const JITSI_CONFERENCE_URL_KEY = Symbol('url');
|
||||
|
||||
export const TRIGGER_READY_TO_CLOSE_REASONS = {
|
||||
'dialog.sessTerminatedReason': 'The meeting has been terminated',
|
||||
'lobby.lobbyClosed': 'Lobby room closed.'
|
||||
};
|
||||
|
||||
/**
|
||||
* Conference leave reasons.
|
||||
*/
|
||||
export const CONFERENCE_LEAVE_REASONS = {
|
||||
SWITCH_ROOM: 'switch_room',
|
||||
UNRECOVERABLE_ERROR: 'unrecoverable_error'
|
||||
};
|
||||
|
||||
/**
|
||||
* The ID of the notification that is shown when the user is muted by focus.
|
||||
*/
|
||||
export const START_MUTED_NOTIFICATION_ID = 'start-muted';
|
||||
620
react/features/base/conference/functions.ts
Normal file
620
react/features/base/conference/functions.ts
Normal file
@@ -0,0 +1,620 @@
|
||||
import { sha512_256 as sha512 } from 'js-sha512';
|
||||
import { upperFirst, words } from 'lodash-es';
|
||||
|
||||
import { getName } from '../../app/functions';
|
||||
import { IReduxState, IStore } from '../../app/types';
|
||||
import { showNotification } from '../../notifications/actions';
|
||||
import { NOTIFICATION_TIMEOUT_TYPE } from '../../notifications/constants';
|
||||
import { determineTranscriptionLanguage } from '../../transcribing/functions';
|
||||
import { IStateful } from '../app/types';
|
||||
import { JitsiTrackErrors } from '../lib-jitsi-meet';
|
||||
import { setAudioMuted, setVideoMuted } from '../media/actions';
|
||||
import { VIDEO_MUTISM_AUTHORITY } from '../media/constants';
|
||||
import {
|
||||
participantJoined,
|
||||
participantLeft
|
||||
} from '../participants/actions';
|
||||
import { getLocalParticipant } from '../participants/functions';
|
||||
import { toState } from '../redux/functions';
|
||||
import {
|
||||
appendURLParam,
|
||||
getBackendSafePath,
|
||||
safeDecodeURIComponent
|
||||
} from '../util/uri';
|
||||
|
||||
import { setObfuscatedRoom } from './actions';
|
||||
import {
|
||||
AVATAR_URL_COMMAND,
|
||||
EMAIL_COMMAND,
|
||||
JITSI_CONFERENCE_URL_KEY,
|
||||
START_MUTED_NOTIFICATION_ID
|
||||
} from './constants';
|
||||
import logger from './logger';
|
||||
import { IJitsiConference } from './reducer';
|
||||
|
||||
/**
|
||||
* Returns root conference state.
|
||||
*
|
||||
* @param {IReduxState} state - Global state.
|
||||
* @returns {Object} Conference state.
|
||||
*/
|
||||
export const getConferenceState = (state: IReduxState) => state['features/base/conference'];
|
||||
|
||||
/**
|
||||
* Attach a set of local tracks to a conference.
|
||||
*
|
||||
* @param {JitsiConference} conference - Conference instance.
|
||||
* @param {JitsiLocalTrack[]} localTracks - List of local media tracks.
|
||||
* @protected
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function _addLocalTracksToConference(
|
||||
conference: IJitsiConference,
|
||||
localTracks: Array<Object>) {
|
||||
const conferenceLocalTracks = conference.getLocalTracks();
|
||||
const promises = [];
|
||||
|
||||
for (const track of localTracks) {
|
||||
// XXX The library lib-jitsi-meet may be draconian, for example, when
|
||||
// adding one and the same video track multiple times.
|
||||
if (conferenceLocalTracks.indexOf(track) === -1) {
|
||||
promises.push(
|
||||
conference.addTrack(track).catch((err: Error) => {
|
||||
_reportError(
|
||||
'Failed to add local track to conference',
|
||||
err);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic shared between web and RN which processes the {@code USER_JOINED}
|
||||
* conference event and dispatches either {@link participantJoined} or
|
||||
* {@link hiddenParticipantJoined}.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @param {JitsiMeetConference} conference - The conference for which the
|
||||
* {@code USER_JOINED} event is being processed.
|
||||
* @param {JitsiParticipant} user - The user who has just joined.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function commonUserJoinedHandling(
|
||||
{ dispatch }: { dispatch: IStore['dispatch']; },
|
||||
conference: IJitsiConference,
|
||||
user: any) {
|
||||
const id = user.getId();
|
||||
const displayName = user.getDisplayName();
|
||||
|
||||
if (!user.isHidden()) {
|
||||
const isReplacing = user?.isReplacing();
|
||||
const isPromoted = conference?.getMetadataHandler().getMetadata()?.visitors?.promoted?.[id];
|
||||
|
||||
// the identity and avatar come from jwt and never change in the presence
|
||||
dispatch(participantJoined({
|
||||
avatarURL: user.getIdentity()?.user?.avatar,
|
||||
botType: user.getBotType(),
|
||||
conference,
|
||||
id,
|
||||
name: displayName,
|
||||
presence: user.getStatus(),
|
||||
role: user.getRole(),
|
||||
isPromoted,
|
||||
isReplacing,
|
||||
sources: user.getSources()
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic shared between web and RN which processes the {@code USER_LEFT}
|
||||
* conference event and dispatches either {@link participantLeft} or
|
||||
* {@link hiddenParticipantLeft}.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @param {JitsiMeetConference} conference - The conference for which the
|
||||
* {@code USER_LEFT} event is being processed.
|
||||
* @param {JitsiParticipant} user - The user who has just left.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function commonUserLeftHandling(
|
||||
{ dispatch }: { dispatch: IStore['dispatch']; },
|
||||
conference: IJitsiConference,
|
||||
user: any) {
|
||||
const id = user.getId();
|
||||
|
||||
if (!user.isHidden()) {
|
||||
const isReplaced = user.isReplaced?.();
|
||||
|
||||
dispatch(participantLeft(id, conference, { isReplaced }));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates a specific predicate for each {@link JitsiConference} known to the
|
||||
* redux state features/base/conference while it returns {@code true}.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store, state, or
|
||||
* {@code getState} function.
|
||||
* @param {Function} predicate - The predicate to evaluate for each
|
||||
* {@code JitsiConference} know to the redux state features/base/conference
|
||||
* while it returns {@code true}.
|
||||
* @returns {boolean} If the specified {@code predicate} returned {@code true}
|
||||
* for all {@code JitsiConference} instances known to the redux state
|
||||
* features/base/conference.
|
||||
*/
|
||||
export function forEachConference(
|
||||
stateful: IStateful,
|
||||
predicate: (a: any, b: URL) => boolean) {
|
||||
const state = getConferenceState(toState(stateful));
|
||||
|
||||
for (const v of Object.values(state)) {
|
||||
// Does the value of the base/conference's property look like a
|
||||
// JitsiConference?
|
||||
if (v && typeof v === 'object') {
|
||||
const url: URL = v[JITSI_CONFERENCE_URL_KEY];
|
||||
|
||||
// XXX The Web version of Jitsi Meet does not utilize
|
||||
// JITSI_CONFERENCE_URL_KEY at the time of this writing. An
|
||||
// alternative is necessary then to recognize JitsiConference
|
||||
// instances and myUserId is as good as any other property.
|
||||
if ((url || typeof v.myUserId === 'function')
|
||||
&& !predicate(v, url)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display name of the conference.
|
||||
*
|
||||
* @param {IStateful} stateful - Reference that can be resolved to Redux
|
||||
* state with the {@code toState} function.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getConferenceName(stateful: IStateful): string {
|
||||
const state = toState(stateful);
|
||||
const { callee } = state['features/base/jwt'];
|
||||
const { callDisplayName } = state['features/base/config'];
|
||||
const { localSubject, pendingSubjectChange, room, subject } = getConferenceState(state);
|
||||
|
||||
return (localSubject
|
||||
|| pendingSubjectChange
|
||||
|| subject
|
||||
|| callDisplayName
|
||||
|| callee?.name
|
||||
|| (room && safeStartCase(safeDecodeURIComponent(room)))) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the conference formatted for the title.
|
||||
*
|
||||
* @param {IStateful} stateful - Reference that can be resolved to Redux state with the {@code toState}
|
||||
* function.
|
||||
* @returns {string} - The name of the conference formatted for the title.
|
||||
*/
|
||||
export function getConferenceNameForTitle(stateful: IStateful) {
|
||||
return safeStartCase(safeDecodeURIComponent(getConferenceState(toState(stateful)).room ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object aggregating the conference options.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store state.
|
||||
* @returns {Object} - Options object.
|
||||
*/
|
||||
export function getConferenceOptions(stateful: IStateful) {
|
||||
const state = toState(stateful);
|
||||
|
||||
const config = state['features/base/config'];
|
||||
const { locationURL } = state['features/base/connection'];
|
||||
const { defaultTranscriptionLanguage } = state['features/dynamic-branding'];
|
||||
const { tenant } = state['features/base/jwt'];
|
||||
const { email, name: nick } = getLocalParticipant(state) ?? {};
|
||||
const options: any = { ...config };
|
||||
|
||||
if (tenant) {
|
||||
options.siteID = tenant;
|
||||
}
|
||||
|
||||
if (options.enableDisplayNameInStats && nick) {
|
||||
options.statisticsDisplayName = nick;
|
||||
}
|
||||
|
||||
if (options.enableEmailInStats && email) {
|
||||
options.statisticsId = email;
|
||||
}
|
||||
|
||||
if (locationURL) {
|
||||
options.confID = `${locationURL.host}${getBackendSafePath(locationURL.pathname)}`;
|
||||
}
|
||||
|
||||
options.applicationName = getName();
|
||||
options.transcriptionLanguage
|
||||
= defaultTranscriptionLanguage ?? determineTranscriptionLanguage(options);
|
||||
|
||||
// Disable analytics, if requested.
|
||||
if (options.disableThirdPartyRequests) {
|
||||
delete config.analytics?.scriptURLs;
|
||||
delete config.analytics?.amplitudeAPPKey;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the restored conference options if anything is available to be restored or undefined.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store state.
|
||||
* @returns {Object?}
|
||||
*/
|
||||
export function restoreConferenceOptions(stateful: IStateful) {
|
||||
const config = toState(stateful)['features/base/config'];
|
||||
|
||||
if (config.oldConfig) {
|
||||
return {
|
||||
hosts: {
|
||||
domain: config.oldConfig.hosts.domain,
|
||||
muc: config.oldConfig.hosts.muc
|
||||
},
|
||||
focusUserJid: config.oldConfig.focusUserJid,
|
||||
disableFocus: false,
|
||||
bosh: config.oldConfig.bosh,
|
||||
websocket: config.oldConfig.websocket,
|
||||
oldConfig: undefined
|
||||
};
|
||||
}
|
||||
|
||||
// nothing to return
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the global config (that is, window.config) with XMPP configuration required to join as a visitor.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store state.
|
||||
* @param {string|undefined} vnode - The received parameters.
|
||||
* @param {string} focusJid - The received parameters.
|
||||
* @param {string|undefined} username - The received parameters.
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function getVisitorOptions(stateful: IStateful, vnode: string, focusJid: string, username: string) {
|
||||
const config = toState(stateful)['features/base/config'];
|
||||
|
||||
if (!config?.hosts) {
|
||||
logger.warn('Wrong configuration, missing hosts.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vnode) {
|
||||
// this is redirecting back to main, lets restore config
|
||||
// not updating disableFocus, as if the room capacity is full the promotion to the main room will fail
|
||||
// and the visitor will be redirected back to a vnode from jicofo
|
||||
if (config.oldConfig && username) {
|
||||
return {
|
||||
hosts: config.oldConfig.hosts,
|
||||
focusUserJid: focusJid,
|
||||
disableLocalStatsBroadcast: false,
|
||||
bosh: config.oldConfig.bosh && appendURLParam(config.oldConfig.bosh, 'customusername', username),
|
||||
p2p: config.oldConfig.p2p,
|
||||
websocket: config.oldConfig.websocket
|
||||
&& appendURLParam(config.oldConfig.websocket, 'customusername', username),
|
||||
oldConfig: undefined // clears it up
|
||||
};
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const oldConfig = {
|
||||
hosts: {
|
||||
domain: ''
|
||||
},
|
||||
focusUserJid: config.focusUserJid,
|
||||
bosh: config.bosh,
|
||||
p2p: config.p2p,
|
||||
websocket: config.websocket
|
||||
};
|
||||
|
||||
// copy original hosts, to make sure we do not use a modified one later
|
||||
Object.assign(oldConfig.hosts, config.hosts);
|
||||
|
||||
const domain = `${vnode}.meet.jitsi`;
|
||||
|
||||
return {
|
||||
oldConfig,
|
||||
hosts: {
|
||||
domain,
|
||||
muc: config.hosts.muc.replace(oldConfig.hosts.domain, domain)
|
||||
},
|
||||
focusUserJid: focusJid,
|
||||
disableFocus: true, // This flag disables sending the initial conference request
|
||||
disableLocalStatsBroadcast: true,
|
||||
bosh: config.bosh && appendURLParam(config.bosh, 'vnode', vnode),
|
||||
p2p: {
|
||||
...config.p2p,
|
||||
enabled: false
|
||||
},
|
||||
websocket: config.websocket && appendURLParam(config.websocket, 'vnode', vnode)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UTC timestamp when the first participant joined the conference.
|
||||
*
|
||||
* @param {IStateful} stateful - Reference that can be resolved to Redux
|
||||
* state with the {@code toState} function.
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getConferenceTimestamp(stateful: IStateful) {
|
||||
const state = toState(stateful);
|
||||
const { conferenceTimestamp } = getConferenceState(state);
|
||||
|
||||
return conferenceTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@code JitsiConference} which is joining or joined and is
|
||||
* not leaving. Please note the contrast with merely reading the
|
||||
* {@code conference} state of the feature base/conference which is not joining
|
||||
* but may be leaving already.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store, state, or
|
||||
* {@code getState} function.
|
||||
* @returns {JitsiConference|undefined}
|
||||
*/
|
||||
export function getCurrentConference(stateful: IStateful): IJitsiConference | undefined {
|
||||
const { conference, joining, leaving, membersOnly, passwordRequired }
|
||||
= getConferenceState(toState(stateful));
|
||||
|
||||
// There is a precedence
|
||||
if (conference) {
|
||||
return conference === leaving ? undefined : conference;
|
||||
}
|
||||
|
||||
return joining || passwordRequired || membersOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current conference is a P2P connection.
|
||||
* Will return `false` if it's a JVB one, and `null` if there is no conference.
|
||||
*
|
||||
* @param {IStateful} stateful - The redux store, state, or
|
||||
* {@code getState} function.
|
||||
* @returns {boolean|null}
|
||||
*/
|
||||
export function isP2pActive(stateful: IStateful): boolean | null {
|
||||
const conference = getCurrentConference(toState(stateful));
|
||||
|
||||
if (!conference) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return conference.isP2PActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stored room name.
|
||||
*
|
||||
* @param {IReduxState} state - The current state of the app.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getRoomName(state: IReduxState) {
|
||||
return getConferenceState(state).room;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscated room name or create and persist it if it doesn't exists.
|
||||
*
|
||||
* @param {IReduxState} state - The current state of the app.
|
||||
* @param {Function} dispatch - The Redux dispatch function.
|
||||
* @returns {string} - Obfuscated room name.
|
||||
*/
|
||||
export function getOrCreateObfuscatedRoomName(state: IReduxState, dispatch: IStore['dispatch']) {
|
||||
let { obfuscatedRoom } = getConferenceState(state);
|
||||
const { obfuscatedRoomSource } = getConferenceState(state);
|
||||
const room = getRoomName(state);
|
||||
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
|
||||
// On native mobile the store doesn't clear when joining a new conference so we might have the obfuscatedRoom
|
||||
// stored even though a different room was joined.
|
||||
// Check if the obfuscatedRoom was already computed for the current room.
|
||||
if (!obfuscatedRoom || (obfuscatedRoomSource !== room)) {
|
||||
obfuscatedRoom = sha512(room);
|
||||
dispatch(setObfuscatedRoom(obfuscatedRoom, room));
|
||||
}
|
||||
|
||||
return obfuscatedRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analytics may require an obfuscated room name, this functions decides based on a config if the normal or
|
||||
* obfuscated room name should be returned.
|
||||
*
|
||||
* @param {IReduxState} state - The current state of the app.
|
||||
* @param {Function} dispatch - The Redux dispatch function.
|
||||
* @returns {string} - Analytics room name.
|
||||
*/
|
||||
export function getAnalyticsRoomName(state: IReduxState, dispatch: IStore['dispatch']) {
|
||||
const { analysis: { obfuscateRoomName = false } = {} } = state['features/base/config'];
|
||||
|
||||
if (obfuscateRoomName) {
|
||||
return getOrCreateObfuscatedRoomName(state, dispatch);
|
||||
}
|
||||
|
||||
return getRoomName(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an error thrown by the backend (i.e. {@code lib-jitsi-meet}) while
|
||||
* manipulating a conference participant (e.g. Pin or select participant).
|
||||
*
|
||||
* @param {Error} err - The Error which was thrown by the backend while
|
||||
* manipulating a conference participant and which is to be handled.
|
||||
* @protected
|
||||
* @returns {void}
|
||||
*/
|
||||
export function _handleParticipantError(err: Error) {
|
||||
// XXX DataChannels are initialized at some later point when the conference
|
||||
// has multiple participants, but code that pins or selects a participant
|
||||
// might be executed before. So here we're swallowing a particular error.
|
||||
// TODO Lib-jitsi-meet should be fixed to not throw such an exception in
|
||||
// these scenarios.
|
||||
if (err.message !== 'Data channels support is disabled!') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a specific string is a valid room name.
|
||||
*
|
||||
* @param {(string|undefined)} room - The name of the conference room to check
|
||||
* for validity.
|
||||
* @returns {boolean} If the specified room name is valid, then true; otherwise,
|
||||
* false.
|
||||
*/
|
||||
export function isRoomValid(room?: string) {
|
||||
return typeof room === 'string' && room !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a set of local tracks from a conference.
|
||||
*
|
||||
* @param {JitsiConference} conference - Conference instance.
|
||||
* @param {JitsiLocalTrack[]} localTracks - List of local media tracks.
|
||||
* @protected
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function _removeLocalTracksFromConference(
|
||||
conference: IJitsiConference,
|
||||
localTracks: Array<Object>) {
|
||||
return Promise.all(localTracks.map(track =>
|
||||
conference.removeTrack(track)
|
||||
.catch((err: Error) => {
|
||||
// Local track might be already disposed by direct
|
||||
// JitsiTrack#dispose() call. So we should ignore this error
|
||||
// here.
|
||||
if (err.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
|
||||
_reportError(
|
||||
'Failed to remove local track from conference',
|
||||
err);
|
||||
}
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a specific Error with a specific error message. While the
|
||||
* implementation merely logs the specified msg and err via the console at the
|
||||
* time of this writing, the intention of the function is to abstract the
|
||||
* reporting of errors and facilitate elaborating on it in the future.
|
||||
*
|
||||
* @param {string} msg - The error message to report.
|
||||
* @param {Error} err - The Error to report.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _reportError(msg: string, err: Error) {
|
||||
// TODO This is a good point to call some global error handler when we have
|
||||
// one.
|
||||
logger.error(msg, err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a representation of the local participant such as her avatar (URL),
|
||||
* email address, and display name to (the remote participants of) a specific
|
||||
* conference.
|
||||
*
|
||||
* @param {Function|Object} stateful - The redux store, state, or
|
||||
* {@code getState} function.
|
||||
* @param {JitsiConference} conference - The {@code JitsiConference} to which
|
||||
* the representation of the local participant is to be sent.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function sendLocalParticipant(
|
||||
stateful: IStateful,
|
||||
conference?: IJitsiConference) {
|
||||
const {
|
||||
avatarURL,
|
||||
email,
|
||||
features,
|
||||
name
|
||||
} = getLocalParticipant(stateful) ?? {};
|
||||
|
||||
avatarURL && conference?.sendCommand(AVATAR_URL_COMMAND, {
|
||||
value: avatarURL
|
||||
});
|
||||
email && conference?.sendCommand(EMAIL_COMMAND, {
|
||||
value: email
|
||||
});
|
||||
|
||||
if (features && features['screen-sharing'] === 'true') {
|
||||
conference?.setLocalParticipantProperty('features_screen-sharing', true);
|
||||
}
|
||||
|
||||
conference?.setDisplayName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* A safe implementation of lodash#startCase that doesn't deburr the string.
|
||||
*
|
||||
* NOTE: According to lodash roadmap, lodash v5 will have this function.
|
||||
*
|
||||
* Code based on https://github.com/lodash/lodash/blob/master/startCase.js.
|
||||
*
|
||||
* @param {string} s - The string to do start case on.
|
||||
* @returns {string}
|
||||
*/
|
||||
function safeStartCase(s = '') {
|
||||
return words(`${s}`.replace(/['\u2019]/g, '')).reduce(
|
||||
(result, word, index) => result + (index ? ' ' : '') + upperFirst(word)
|
||||
, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the mute state of the track based on the start muted policy.
|
||||
*
|
||||
* @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
|
||||
* @param {Function} dispatch - Redux dispatch function.
|
||||
* @param {boolean} isAudio - Whether the track is audio or video.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function updateTrackMuteState(stateful: IStateful, dispatch: IStore['dispatch'], isAudio: boolean) {
|
||||
const state = toState(stateful);
|
||||
const mutedPolicyKey = isAudio ? 'startAudioMutedPolicy' : 'startVideoMutedPolicy';
|
||||
const mutedPolicyValue = state['features/base/conference'][mutedPolicyKey];
|
||||
|
||||
// Currently, the policy only supports force muting others, not unmuting them.
|
||||
if (!mutedPolicyValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
let muteStateUpdated = false;
|
||||
const { muted } = isAudio ? state['features/base/media'].audio : state['features/base/media'].video;
|
||||
|
||||
if (isAudio && !Boolean(muted)) {
|
||||
dispatch(setAudioMuted(mutedPolicyValue, true));
|
||||
muteStateUpdated = true;
|
||||
} else if (!isAudio && !Boolean(muted)) {
|
||||
// TODO: Add a new authority for video mutism for the moderator case.
|
||||
dispatch(setVideoMuted(mutedPolicyValue, VIDEO_MUTISM_AUTHORITY.USER, true));
|
||||
muteStateUpdated = true;
|
||||
}
|
||||
|
||||
if (muteStateUpdated) {
|
||||
dispatch(showNotification({
|
||||
titleKey: 'notify.mutedTitle',
|
||||
descriptionKey: 'notify.muted',
|
||||
uid: START_MUTED_NOTIFICATION_ID // use the same id, to make sure we show one notification
|
||||
}, NOTIFICATION_TIMEOUT_TYPE.SHORT));
|
||||
}
|
||||
}
|
||||
3
react/features/base/conference/logger.ts
Normal file
3
react/features/base/conference/logger.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { getLogger } from '../logging/functions';
|
||||
|
||||
export default getLogger('features/base/conference');
|
||||
795
react/features/base/conference/middleware.any.ts
Normal file
795
react/features/base/conference/middleware.any.ts
Normal file
@@ -0,0 +1,795 @@
|
||||
import i18n from 'i18next';
|
||||
import { AnyAction } from 'redux';
|
||||
|
||||
// @ts-ignore
|
||||
import { MIN_ASSUMED_BANDWIDTH_BPS } from '../../../../modules/API/constants';
|
||||
import {
|
||||
ACTION_PINNED,
|
||||
ACTION_UNPINNED,
|
||||
createNotAllowedErrorEvent,
|
||||
createOfferAnswerFailedEvent,
|
||||
createPinnedEvent
|
||||
} from '../../analytics/AnalyticsEvents';
|
||||
import { sendAnalytics } from '../../analytics/functions';
|
||||
import { reloadNow } from '../../app/actions';
|
||||
import { IStore } from '../../app/types';
|
||||
import { removeLobbyChatParticipant } from '../../chat/actions.any';
|
||||
import { openDisplayNamePrompt } from '../../display-name/actions';
|
||||
import { isVpaasMeeting } from '../../jaas/functions';
|
||||
import { clearNotifications, showErrorNotification, showNotification } from '../../notifications/actions';
|
||||
import { NOTIFICATION_TIMEOUT_TYPE } from '../../notifications/constants';
|
||||
import { INotificationProps } from '../../notifications/types';
|
||||
import { hasDisplayName } from '../../prejoin/utils';
|
||||
import { stopLocalVideoRecording } from '../../recording/actions.any';
|
||||
import LocalRecordingManager from '../../recording/components/Recording/LocalRecordingManager';
|
||||
import { AudioMixerEffect } from '../../stream-effects/audio-mixer/AudioMixerEffect';
|
||||
import { iAmVisitor } from '../../visitors/functions';
|
||||
import { overwriteConfig } from '../config/actions';
|
||||
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED, CONNECTION_WILL_CONNECT } from '../connection/actionTypes';
|
||||
import { connectionDisconnected, disconnect } from '../connection/actions';
|
||||
import { validateJwt } from '../jwt/functions';
|
||||
import { JitsiConferenceErrors, JitsiConferenceEvents, JitsiConnectionErrors } from '../lib-jitsi-meet';
|
||||
import { MEDIA_TYPE } from '../media/constants';
|
||||
import { PARTICIPANT_UPDATED, PIN_PARTICIPANT } from '../participants/actionTypes';
|
||||
import { PARTICIPANT_ROLE } from '../participants/constants';
|
||||
import {
|
||||
getLocalParticipant,
|
||||
getParticipantById,
|
||||
getPinnedParticipant
|
||||
} from '../participants/functions';
|
||||
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
||||
import StateListenerRegistry from '../redux/StateListenerRegistry';
|
||||
import { TRACK_ADDED, TRACK_REMOVED } from '../tracks/actionTypes';
|
||||
import { parseURIString } from '../util/uri';
|
||||
|
||||
import {
|
||||
CONFERENCE_FAILED,
|
||||
CONFERENCE_JOINED,
|
||||
CONFERENCE_SUBJECT_CHANGED,
|
||||
CONFERENCE_WILL_LEAVE,
|
||||
P2P_STATUS_CHANGED,
|
||||
SEND_TONES,
|
||||
SET_ASSUMED_BANDWIDTH_BPS,
|
||||
SET_PENDING_SUBJECT_CHANGE,
|
||||
SET_ROOM
|
||||
} from './actionTypes';
|
||||
import {
|
||||
authStatusChanged,
|
||||
conferenceFailed,
|
||||
conferenceWillLeave,
|
||||
createConference,
|
||||
setLocalSubject,
|
||||
setSubject,
|
||||
updateConferenceMetadata
|
||||
} from './actions';
|
||||
import { CONFERENCE_LEAVE_REASONS } from './constants';
|
||||
import {
|
||||
_addLocalTracksToConference,
|
||||
_removeLocalTracksFromConference,
|
||||
forEachConference,
|
||||
getCurrentConference,
|
||||
restoreConferenceOptions
|
||||
} from './functions';
|
||||
import logger from './logger';
|
||||
import { IConferenceMetadata } from './reducer';
|
||||
|
||||
/**
|
||||
* Handler for before unload event.
|
||||
*/
|
||||
let beforeUnloadHandler: ((e?: any) => void) | undefined;
|
||||
|
||||
/**
|
||||
* Implements the middleware of the feature base/conference.
|
||||
*
|
||||
* @param {Store} store - The redux store.
|
||||
* @returns {Function}
|
||||
*/
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
case CONFERENCE_FAILED:
|
||||
return _conferenceFailed(store, next, action);
|
||||
|
||||
case CONFERENCE_JOINED:
|
||||
return _conferenceJoined(store, next, action);
|
||||
|
||||
case CONNECTION_ESTABLISHED:
|
||||
return _connectionEstablished(store, next, action);
|
||||
|
||||
case CONNECTION_FAILED:
|
||||
return _connectionFailed(store, next, action);
|
||||
|
||||
case CONNECTION_WILL_CONNECT:
|
||||
// we are starting a new join process, let's clear the error notifications if any from any previous attempt
|
||||
store.dispatch(clearNotifications());
|
||||
break;
|
||||
|
||||
case CONFERENCE_SUBJECT_CHANGED:
|
||||
return _conferenceSubjectChanged(store, next, action);
|
||||
|
||||
case CONFERENCE_WILL_LEAVE:
|
||||
_conferenceWillLeave(store);
|
||||
break;
|
||||
|
||||
case P2P_STATUS_CHANGED:
|
||||
return _p2pStatusChanged(next, action);
|
||||
|
||||
case PARTICIPANT_UPDATED:
|
||||
return _updateLocalParticipantInConference(store, next, action);
|
||||
|
||||
case PIN_PARTICIPANT:
|
||||
return _pinParticipant(store, next, action);
|
||||
|
||||
case SEND_TONES:
|
||||
return _sendTones(store, next, action);
|
||||
|
||||
case SET_ROOM:
|
||||
return _setRoom(store, next, action);
|
||||
|
||||
case TRACK_ADDED:
|
||||
case TRACK_REMOVED:
|
||||
return _trackAddedOrRemoved(store, next, action);
|
||||
|
||||
case SET_ASSUMED_BANDWIDTH_BPS:
|
||||
return _setAssumedBandwidthBps(store, next, action);
|
||||
}
|
||||
|
||||
return next(action);
|
||||
});
|
||||
|
||||
/**
|
||||
* Set up state change listener to perform maintenance tasks when the conference
|
||||
* is left or failed.
|
||||
*/
|
||||
StateListenerRegistry.register(
|
||||
state => getCurrentConference(state),
|
||||
(conference, { dispatch }, previousConference): void => {
|
||||
if (conference && !previousConference) {
|
||||
conference.on(JitsiConferenceEvents.METADATA_UPDATED, (metadata: IConferenceMetadata) => {
|
||||
dispatch(updateConferenceMetadata(metadata));
|
||||
});
|
||||
}
|
||||
|
||||
if (conference !== previousConference) {
|
||||
dispatch(updateConferenceMetadata(null));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Makes sure to leave a failed conference in order to release any allocated
|
||||
* resources like peer connections, emit participant left events, etc.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code CONFERENCE_FAILED} which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _conferenceFailed({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const { conference, error } = action;
|
||||
|
||||
const result = next(action);
|
||||
const { enableForcedReload } = getState()['features/base/config'];
|
||||
|
||||
if (LocalRecordingManager.isRecordingLocally()) {
|
||||
dispatch(stopLocalVideoRecording());
|
||||
}
|
||||
|
||||
// Handle specific failure reasons.
|
||||
switch (error.name) {
|
||||
case JitsiConferenceErrors.CONFERENCE_RESTARTED: {
|
||||
if (enableForcedReload) {
|
||||
dispatch(showErrorNotification({
|
||||
description: 'Restart initiated because of a bridge failure',
|
||||
titleKey: 'dialog.sessionRestarted'
|
||||
}));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case JitsiConferenceErrors.CONNECTION_ERROR: {
|
||||
const [ msg ] = error.params;
|
||||
|
||||
dispatch(connectionDisconnected(getState()['features/base/connection'].connection));
|
||||
dispatch(showErrorNotification({
|
||||
descriptionArguments: { msg },
|
||||
descriptionKey: msg ? 'dialog.connectErrorWithMsg' : 'dialog.connectError',
|
||||
titleKey: 'connection.CONNFAIL'
|
||||
}));
|
||||
|
||||
break;
|
||||
}
|
||||
case JitsiConferenceErrors.CONFERENCE_MAX_USERS: {
|
||||
dispatch(showErrorNotification({
|
||||
hideErrorSupportLink: true,
|
||||
descriptionKey: 'dialog.maxUsersLimitReached',
|
||||
titleKey: 'dialog.maxUsersLimitReachedTitle'
|
||||
}));
|
||||
|
||||
// In case of max users(it can be from a visitor node), let's restore
|
||||
// oldConfig if any as we will be back to the main prosody.
|
||||
const newConfig = restoreConferenceOptions(getState);
|
||||
|
||||
if (newConfig) {
|
||||
dispatch(overwriteConfig(newConfig));
|
||||
dispatch(conferenceWillLeave(conference));
|
||||
|
||||
conference.leave()
|
||||
.then(() => dispatch(disconnect()));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case JitsiConferenceErrors.NOT_ALLOWED_ERROR: {
|
||||
const [ type, msg ] = error.params;
|
||||
|
||||
let descriptionKey;
|
||||
let titleKey = 'dialog.tokenAuthFailed';
|
||||
|
||||
if (type === JitsiConferenceErrors.AUTH_ERROR_TYPES.NO_MAIN_PARTICIPANTS) {
|
||||
descriptionKey = 'visitors.notification.noMainParticipantsDescription';
|
||||
titleKey = 'visitors.notification.noMainParticipantsTitle';
|
||||
} else if (type === JitsiConferenceErrors.AUTH_ERROR_TYPES.NO_VISITORS_LOBBY) {
|
||||
descriptionKey = 'visitors.notification.noVisitorLobby';
|
||||
} else if (type === JitsiConferenceErrors.AUTH_ERROR_TYPES.PROMOTION_NOT_ALLOWED) {
|
||||
descriptionKey = 'visitors.notification.notAllowedPromotion';
|
||||
} else if (type === JitsiConferenceErrors.AUTH_ERROR_TYPES.ROOM_CREATION_RESTRICTION) {
|
||||
descriptionKey = 'dialog.errorRoomCreationRestriction';
|
||||
}
|
||||
|
||||
dispatch(showErrorNotification({
|
||||
descriptionKey,
|
||||
hideErrorSupportLink: true,
|
||||
titleKey
|
||||
}));
|
||||
|
||||
sendAnalytics(createNotAllowedErrorEvent(type, msg));
|
||||
|
||||
break;
|
||||
}
|
||||
case JitsiConferenceErrors.OFFER_ANSWER_FAILED:
|
||||
sendAnalytics(createOfferAnswerFailedEvent());
|
||||
break;
|
||||
}
|
||||
|
||||
!error.recoverable
|
||||
&& conference?.leave(CONFERENCE_LEAVE_REASONS.UNRECOVERABLE_ERROR).catch((reason: Error) => {
|
||||
// Even though we don't care too much about the failure, it may be
|
||||
// good to know that it happen, so log it (on the info level).
|
||||
logger.info('JitsiConference.leave() rejected with:', reason);
|
||||
});
|
||||
|
||||
// FIXME: Workaround for the web version. Currently, the creation of the
|
||||
// conference is handled by /conference.js and appropriate failure handlers
|
||||
// are set there.
|
||||
if (typeof APP !== 'undefined') {
|
||||
_removeUnloadHandler(getState);
|
||||
}
|
||||
|
||||
if (enableForcedReload
|
||||
&& (error?.name === JitsiConferenceErrors.CONFERENCE_RESTARTED
|
||||
|| error?.name === JitsiConnectionErrors.SHARD_CHANGED_ERROR)) {
|
||||
dispatch(conferenceWillLeave(conference));
|
||||
dispatch(reloadNow());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does extra sync up on properties that may need to be updated after the
|
||||
* conference was joined.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _conferenceJoined({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const result = next(action);
|
||||
const { conference } = action;
|
||||
const { pendingSubjectChange } = getState()['features/base/conference'];
|
||||
const {
|
||||
disableBeforeUnloadHandlers = false,
|
||||
requireDisplayName
|
||||
} = getState()['features/base/config'];
|
||||
|
||||
dispatch(removeLobbyChatParticipant(true));
|
||||
|
||||
pendingSubjectChange && dispatch(setSubject(pendingSubjectChange));
|
||||
|
||||
// FIXME: Very dirty solution. This will work on web only.
|
||||
// When the user closes the window or quits the browser, lib-jitsi-meet
|
||||
// handles the process of leaving the conference. This is temporary solution
|
||||
// that should cover the described use case as part of the effort to
|
||||
// implement the conferenceWillLeave action for web.
|
||||
beforeUnloadHandler = (e?: any) => {
|
||||
if (LocalRecordingManager.isRecordingLocally()) {
|
||||
dispatch(stopLocalVideoRecording());
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
e.returnValue = null;
|
||||
}
|
||||
}
|
||||
dispatch(conferenceWillLeave(conference));
|
||||
};
|
||||
|
||||
if (!iAmVisitor(getState())) {
|
||||
// if a visitor is promoted back to main room and want to join an empty breakout room
|
||||
// we need to send iq to jicofo, so it can join/create the breakout room
|
||||
dispatch(overwriteConfig({ disableFocus: false }));
|
||||
}
|
||||
|
||||
window.addEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', beforeUnloadHandler);
|
||||
|
||||
if (requireDisplayName
|
||||
&& !getLocalParticipant(getState)?.name
|
||||
&& !conference.isHidden()) {
|
||||
dispatch(openDisplayNamePrompt({
|
||||
validateInput: hasDisplayName
|
||||
}));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code CONNECTION_ESTABLISHED} is being dispatched within a specific redux
|
||||
* store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code CONNECTION_ESTABLISHED}
|
||||
* which is being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
async function _connectionEstablished({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const result = next(action);
|
||||
|
||||
const { tokenAuthUrl = false } = getState()['features/base/config'];
|
||||
|
||||
// if there is token auth URL defined and local participant is using jwt
|
||||
// this means it is logged in when connection is established, so we can change the state
|
||||
if (tokenAuthUrl && !isVpaasMeeting(getState())) {
|
||||
let email;
|
||||
|
||||
if (getState()['features/base/jwt'].jwt) {
|
||||
email = getLocalParticipant(getState())?.email;
|
||||
}
|
||||
|
||||
dispatch(authStatusChanged(true, email || ''));
|
||||
}
|
||||
|
||||
// FIXME: Workaround for the web version. Currently, the creation of the
|
||||
// conference is handled by /conference.js.
|
||||
if (typeof APP === 'undefined') {
|
||||
dispatch(createConference());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs jwt validation errors from xmpp and from the client-side validator.
|
||||
*
|
||||
* @param {string} message - The error message from xmpp.
|
||||
* @param {string} errors - The detailed errors.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _logJwtErrors(message: string, errors: string) {
|
||||
message && logger.error(`JWT error: ${message}`);
|
||||
errors && logger.error('JWT parsing errors:', errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code CONNECTION_FAILED} is being dispatched within a specific redux
|
||||
* store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code CONNECTION_FAILED} which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _connectionFailed({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const { connection, error } = action;
|
||||
const { jwt } = getState()['features/base/jwt'];
|
||||
|
||||
if (jwt) {
|
||||
const errors: string = validateJwt(jwt).map((err: any) =>
|
||||
i18n.t(`dialog.tokenAuthFailedReason.${err.key}`, err.args))
|
||||
.join(' ');
|
||||
|
||||
_logJwtErrors(error.message, errors);
|
||||
|
||||
// do not show the notification when we will prompt the user
|
||||
// for username and password
|
||||
if (error.name === JitsiConnectionErrors.PASSWORD_REQUIRED) {
|
||||
dispatch(showErrorNotification({
|
||||
descriptionKey: errors ? 'dialog.tokenAuthFailedWithReasons' : 'dialog.tokenAuthFailed',
|
||||
descriptionArguments: { reason: errors },
|
||||
titleKey: 'dialog.tokenAuthFailedTitle'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (error.name === JitsiConnectionErrors.CONFERENCE_REQUEST_FAILED) {
|
||||
let notificationAction: Function = showNotification;
|
||||
const notificationProps = {
|
||||
customActionNameKey: [ 'dialog.rejoinNow' ],
|
||||
customActionHandler: [ () => dispatch(reloadNow()) ],
|
||||
descriptionKey: 'notify.connectionFailed'
|
||||
} as INotificationProps;
|
||||
|
||||
const { locationURL = { href: '' } as URL } = getState()['features/base/connection'];
|
||||
const { tenant = '' } = parseURIString(locationURL.href) || {};
|
||||
|
||||
if (tenant.startsWith('-') || tenant.endsWith('-')) {
|
||||
notificationProps.descriptionKey = 'notify.invalidTenantHyphenDescription';
|
||||
notificationProps.titleKey = 'notify.invalidTenant';
|
||||
notificationAction = showErrorNotification;
|
||||
} else if (tenant.length > 63) {
|
||||
notificationProps.descriptionKey = 'notify.invalidTenantLengthDescription';
|
||||
notificationProps.titleKey = 'notify.invalidTenant';
|
||||
notificationAction = showErrorNotification;
|
||||
}
|
||||
|
||||
dispatch(notificationAction(notificationProps, NOTIFICATION_TIMEOUT_TYPE.STICKY));
|
||||
}
|
||||
|
||||
const result = next(action);
|
||||
|
||||
_removeUnloadHandler(getState);
|
||||
|
||||
forEachConference(getState, conference => {
|
||||
// TODO: revisit this
|
||||
// It feels that it would make things easier if JitsiConference
|
||||
// in lib-jitsi-meet would monitor it's connection and emit
|
||||
// CONFERENCE_FAILED when it's dropped. It has more knowledge on
|
||||
// whether it can recover or not. But because the reload screen
|
||||
// and the retry logic is implemented in the app maybe it can be
|
||||
// left this way for now.
|
||||
if (conference.getConnection() === connection) {
|
||||
// XXX Note that on mobile the error type passed to
|
||||
// connectionFailed is always an object with .name property.
|
||||
// This fact needs to be checked prior to enabling this logic on
|
||||
// web.
|
||||
const conferenceAction = conferenceFailed(conference, error.name);
|
||||
|
||||
// Copy the recoverable flag if set on the CONNECTION_FAILED
|
||||
// action to not emit recoverable action caused by
|
||||
// a non-recoverable one.
|
||||
if (typeof error.recoverable !== 'undefined') {
|
||||
conferenceAction.error.recoverable = error.recoverable;
|
||||
}
|
||||
|
||||
dispatch(conferenceAction);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code CONFERENCE_SUBJECT_CHANGED} is being dispatched within a specific
|
||||
* redux store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code CONFERENCE_SUBJECT_CHANGED}
|
||||
* which is being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _conferenceSubjectChanged({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const result = next(action);
|
||||
const { subject } = getState()['features/base/conference'];
|
||||
|
||||
if (subject) {
|
||||
dispatch({
|
||||
type: SET_PENDING_SUBJECT_CHANGE,
|
||||
subject: undefined
|
||||
});
|
||||
}
|
||||
|
||||
typeof APP === 'object' && APP.API.notifySubjectChanged(subject);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code CONFERENCE_WILL_LEAVE} is being dispatched within a specific redux
|
||||
* store.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} store - The redux store.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _conferenceWillLeave({ getState }: IStore) {
|
||||
_removeUnloadHandler(getState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
|
||||
* is being dispatched within a specific redux store. Pins the specified remote
|
||||
* participant in the associated conference, ignores the local participant.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code PIN_PARTICIPANT} which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _pinParticipant({ getState }: IStore, next: Function, action: AnyAction) {
|
||||
const state = getState();
|
||||
const { conference } = state['features/base/conference'];
|
||||
|
||||
if (!conference) {
|
||||
return next(action);
|
||||
}
|
||||
|
||||
const id = action.participant.id;
|
||||
const participantById = getParticipantById(state, id);
|
||||
const pinnedParticipant = getPinnedParticipant(state);
|
||||
const actionName = id ? ACTION_PINNED : ACTION_UNPINNED;
|
||||
const local
|
||||
= participantById?.local
|
||||
|| (!id && pinnedParticipant?.local);
|
||||
let participantIdForEvent;
|
||||
|
||||
if (local) {
|
||||
participantIdForEvent = local;
|
||||
} else {
|
||||
participantIdForEvent
|
||||
= actionName === ACTION_PINNED ? id : pinnedParticipant?.id;
|
||||
}
|
||||
|
||||
sendAnalytics(createPinnedEvent(
|
||||
actionName,
|
||||
participantIdForEvent,
|
||||
{
|
||||
local,
|
||||
'participant_count': conference.getParticipantCount()
|
||||
}));
|
||||
|
||||
return next(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the unload handler.
|
||||
*
|
||||
* @param {Function} getState - The redux getState function.
|
||||
* @returns {void}
|
||||
*/
|
||||
function _removeUnloadHandler(getState: IStore['getState']) {
|
||||
if (typeof beforeUnloadHandler !== 'undefined') {
|
||||
const { disableBeforeUnloadHandlers = false } = getState()['features/base/config'];
|
||||
|
||||
window.removeEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', beforeUnloadHandler);
|
||||
beforeUnloadHandler = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the specified tones to be played.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code SEND_TONES} which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _sendTones({ getState }: IStore, next: Function, action: AnyAction) {
|
||||
const state = getState();
|
||||
const { conference } = state['features/base/conference'];
|
||||
|
||||
if (conference) {
|
||||
const { duration, tones, pause } = action;
|
||||
|
||||
conference.sendTones(tones, duration, pause);
|
||||
}
|
||||
|
||||
return next(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code SET_ROOM} is being dispatched within a specific
|
||||
* redux store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code SET_ROOM}
|
||||
* which is being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _setRoom({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const state = getState();
|
||||
const { localSubject, subject } = state['features/base/config'];
|
||||
const { room } = action;
|
||||
|
||||
if (room) {
|
||||
// Set the stored subject.
|
||||
localSubject && dispatch(setLocalSubject(localSubject));
|
||||
subject && dispatch(setSubject(subject));
|
||||
}
|
||||
|
||||
return next(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action {@code TRACK_ADDED}
|
||||
* or {@code TRACK_REMOVED} is being dispatched within a specific redux store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code TRACK_ADDED} or
|
||||
* {@code TRACK_REMOVED} which is being dispatched in the specified
|
||||
* {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
async function _trackAddedOrRemoved(store: IStore, next: Function, action: AnyAction) {
|
||||
const track = action.track;
|
||||
|
||||
// TODO All track swapping should happen here instead of conference.js.
|
||||
if (track?.local) {
|
||||
const { getState } = store;
|
||||
const state = getState();
|
||||
const conference = getCurrentConference(state);
|
||||
|
||||
if (conference) {
|
||||
const jitsiTrack = action.track.jitsiTrack;
|
||||
|
||||
if (action.type === TRACK_ADDED) {
|
||||
// If gUM is slow and tracks are created after the user has already joined the conference, avoid
|
||||
// adding the tracks to the conference if the user is a visitor.
|
||||
if (!iAmVisitor(state)) {
|
||||
const { desktopAudioTrack } = state['features/screen-share'];
|
||||
|
||||
// If the user is sharing their screen and has a desktop audio track, we need to replace that with
|
||||
// the audio mixer effect so that the desktop audio is mixed in with the microphone audio.
|
||||
if (typeof APP !== 'undefined' && desktopAudioTrack && track.mediaType === MEDIA_TYPE.AUDIO) {
|
||||
await conference.replaceTrack(desktopAudioTrack, null);
|
||||
const audioMixerEffect = new AudioMixerEffect(desktopAudioTrack);
|
||||
|
||||
await jitsiTrack.setEffect(audioMixerEffect);
|
||||
await conference.replaceTrack(null, jitsiTrack);
|
||||
} else {
|
||||
await _addLocalTracksToConference(conference, [ jitsiTrack ]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await _removeLocalTracksFromConference(conference, [ jitsiTrack ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the conference object when the local participant is updated.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action which is being dispatched in the
|
||||
* specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _updateLocalParticipantInConference({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
||||
const { conference } = getState()['features/base/conference'];
|
||||
const { participant } = action;
|
||||
const result = next(action);
|
||||
|
||||
const localParticipant = getLocalParticipant(getState);
|
||||
|
||||
if (conference && participant.id === localParticipant?.id) {
|
||||
if ('name' in participant) {
|
||||
conference.setDisplayName(participant.name);
|
||||
}
|
||||
|
||||
if ('isSilent' in participant) {
|
||||
conference.setIsSilent(participant.isSilent);
|
||||
}
|
||||
|
||||
if ('role' in participant && participant.role === PARTICIPANT_ROLE.MODERATOR) {
|
||||
const { pendingSubjectChange, subject } = getState()['features/base/conference'];
|
||||
|
||||
// When the local user role is updated to moderator and we have a pending subject change
|
||||
// which was not reflected we need to set it (the first time we tried was before becoming moderator).
|
||||
if (typeof pendingSubjectChange !== 'undefined' && pendingSubjectChange !== subject) {
|
||||
dispatch(setSubject(pendingSubjectChange));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the external API that the action {@code P2P_STATUS_CHANGED}
|
||||
* is being dispatched within a specific redux store.
|
||||
*
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code P2P_STATUS_CHANGED}
|
||||
* which is being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _p2pStatusChanged(next: Function, action: AnyAction) {
|
||||
const result = next(action);
|
||||
|
||||
if (typeof APP !== 'undefined') {
|
||||
APP.API.notifyP2pStatusChanged(action.p2p);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature base/conference that the action
|
||||
* {@code SET_ASSUMED_BANDWIDTH_BPS} is being dispatched within a specific
|
||||
* redux store.
|
||||
*
|
||||
* @param {Store} store - The redux store in which the specified {@code action}
|
||||
* is being dispatched.
|
||||
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
||||
* specified {@code action} to the specified {@code store}.
|
||||
* @param {Action} action - The redux action {@code SET_ASSUMED_BANDWIDTH_BPS}
|
||||
* which is being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The value returned by {@code next(action)}.
|
||||
*/
|
||||
function _setAssumedBandwidthBps({ getState }: IStore, next: Function, action: AnyAction) {
|
||||
const state = getState();
|
||||
const conference = getCurrentConference(state);
|
||||
const payload = Number(action.assumedBandwidthBps);
|
||||
|
||||
const assumedBandwidthBps = isNaN(payload) || payload < MIN_ASSUMED_BANDWIDTH_BPS
|
||||
? MIN_ASSUMED_BANDWIDTH_BPS
|
||||
: payload;
|
||||
|
||||
if (conference) {
|
||||
conference.setAssumedBandwidthBps(assumedBandwidthBps);
|
||||
}
|
||||
|
||||
return next(action);
|
||||
}
|
||||
46
react/features/base/conference/middleware.native.ts
Normal file
46
react/features/base/conference/middleware.native.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { appNavigate } from '../../app/actions.native';
|
||||
import { notifyConferenceFailed } from '../../conference/actions.native';
|
||||
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
||||
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
||||
|
||||
import { CONFERENCE_FAILED } from './actionTypes';
|
||||
import { conferenceLeft } from './actions.native';
|
||||
import { TRIGGER_READY_TO_CLOSE_REASONS } from './constants';
|
||||
|
||||
import './middleware.any';
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
const { dispatch } = store;
|
||||
const { error } = action;
|
||||
|
||||
switch (action.type) {
|
||||
case CONFERENCE_FAILED: {
|
||||
const { getState } = store;
|
||||
const state = getState();
|
||||
const { notifyOnConferenceDestruction = true } = state['features/base/config'];
|
||||
|
||||
if (error?.name !== JitsiConferenceErrors.CONFERENCE_DESTROYED) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!notifyOnConferenceDestruction) {
|
||||
dispatch(conferenceLeft(action.conference));
|
||||
dispatch(appNavigate(undefined));
|
||||
break;
|
||||
}
|
||||
|
||||
const [ reason ] = error.params;
|
||||
|
||||
const reasonKey = Object.keys(TRIGGER_READY_TO_CLOSE_REASONS)[
|
||||
Object.values(TRIGGER_READY_TO_CLOSE_REASONS).indexOf(reason)
|
||||
];
|
||||
|
||||
dispatch(notifyConferenceFailed(reasonKey, () => {
|
||||
dispatch(conferenceLeft(action.conference));
|
||||
dispatch(appNavigate(undefined));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
});
|
||||
218
react/features/base/conference/middleware.web.ts
Normal file
218
react/features/base/conference/middleware.web.ts
Normal file
@@ -0,0 +1,218 @@
|
||||
import i18next from 'i18next';
|
||||
|
||||
import {
|
||||
setPrejoinPageVisibility,
|
||||
setSkipPrejoinOnReload
|
||||
} from '../../prejoin/actions.web';
|
||||
import { isPrejoinPageVisible } from '../../prejoin/functions';
|
||||
import { iAmVisitor } from '../../visitors/functions';
|
||||
import { CONNECTION_DISCONNECTED, CONNECTION_ESTABLISHED } from '../connection/actionTypes';
|
||||
import { hangup } from '../connection/actions.web';
|
||||
import { JitsiConferenceErrors, JitsiConnectionErrors, browser } from '../lib-jitsi-meet';
|
||||
import { gumPending, setInitialGUMPromise } from '../media/actions';
|
||||
import { MEDIA_TYPE } from '../media/constants';
|
||||
import { IGUMPendingState } from '../media/types';
|
||||
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
||||
import { replaceLocalTrack } from '../tracks/actions.any';
|
||||
import { getLocalTracks } from '../tracks/functions.any';
|
||||
|
||||
import {
|
||||
CONFERENCE_FAILED,
|
||||
CONFERENCE_JOINED,
|
||||
CONFERENCE_JOIN_IN_PROGRESS,
|
||||
CONFERENCE_LEFT,
|
||||
KICKED_OUT
|
||||
} from './actionTypes';
|
||||
import { TRIGGER_READY_TO_CLOSE_REASONS } from './constants';
|
||||
import logger from './logger';
|
||||
|
||||
import './middleware.any';
|
||||
|
||||
let screenLock: WakeLockSentinel | undefined;
|
||||
|
||||
/**
|
||||
* Releases the screen lock.
|
||||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function releaseScreenLock() {
|
||||
if (screenLock) {
|
||||
if (!screenLock.released) {
|
||||
logger.debug('Releasing wake lock.');
|
||||
|
||||
try {
|
||||
await screenLock.release();
|
||||
} catch (e) {
|
||||
logger.error(`Error while releasing the screen wake lock: ${e}.`);
|
||||
}
|
||||
}
|
||||
screenLock.removeEventListener('release', onWakeLockReleased);
|
||||
screenLock = undefined;
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a new screen wake lock.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function requestWakeLock() {
|
||||
if (navigator.wakeLock?.request) {
|
||||
navigator.wakeLock.request('screen')
|
||||
.then(lock => {
|
||||
screenLock = lock;
|
||||
screenLock.addEventListener('release', onWakeLockReleased);
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
logger.debug('Wake lock created.');
|
||||
})
|
||||
.catch(e => {
|
||||
logger.error(`Error while requesting wake lock for screen: ${e}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page visibility change handler that re-requests the wake lock if it has been released by the OS.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
async function handleVisibilityChange() {
|
||||
if (screenLock?.released && document.visibilityState === 'visible') {
|
||||
// The screen lock have been released by the OS because of document visibility change. Lets try to request the
|
||||
// wake lock again.
|
||||
await releaseScreenLock();
|
||||
requestWakeLock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wake lock released handler.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function onWakeLockReleased() {
|
||||
logger.debug('Wake lock released');
|
||||
}
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
const { dispatch, getState } = store;
|
||||
const { enableForcedReload } = getState()['features/base/config'];
|
||||
|
||||
switch (action.type) {
|
||||
case CONFERENCE_JOIN_IN_PROGRESS: {
|
||||
dispatch(setPrejoinPageVisibility(false));
|
||||
|
||||
break;
|
||||
}
|
||||
case CONFERENCE_JOINED: {
|
||||
if (enableForcedReload) {
|
||||
dispatch(setSkipPrejoinOnReload(false));
|
||||
}
|
||||
|
||||
requestWakeLock();
|
||||
|
||||
break;
|
||||
}
|
||||
case CONFERENCE_FAILED: {
|
||||
const errorName = action.error?.name;
|
||||
|
||||
if (enableForcedReload
|
||||
&& (errorName === JitsiConferenceErrors.CONFERENCE_RESTARTED
|
||||
|| errorName === JitsiConnectionErrors.SHARD_CHANGED_ERROR)) {
|
||||
dispatch(setSkipPrejoinOnReload(true));
|
||||
}
|
||||
|
||||
if (errorName === JitsiConferenceErrors.CONFERENCE_DESTROYED) {
|
||||
const state = getState();
|
||||
const { notifyOnConferenceDestruction = true } = state['features/base/config'];
|
||||
const [ reason ] = action.error.params;
|
||||
const titlekey = Object.keys(TRIGGER_READY_TO_CLOSE_REASONS)[
|
||||
Object.values(TRIGGER_READY_TO_CLOSE_REASONS).indexOf(reason)
|
||||
];
|
||||
|
||||
dispatch(hangup(true, i18next.t(titlekey) || reason, notifyOnConferenceDestruction));
|
||||
}
|
||||
|
||||
releaseScreenLock();
|
||||
|
||||
break;
|
||||
}
|
||||
case CONFERENCE_LEFT:
|
||||
case KICKED_OUT:
|
||||
releaseScreenLock();
|
||||
|
||||
break;
|
||||
case CONNECTION_DISCONNECTED: {
|
||||
const { initialGUMPromise } = getState()['features/base/media'];
|
||||
|
||||
if (initialGUMPromise) {
|
||||
store.dispatch(setInitialGUMPromise());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CONNECTION_ESTABLISHED: {
|
||||
const { initialGUMPromise } = getState()['features/base/media'];
|
||||
const promise = initialGUMPromise ? initialGUMPromise.promise : Promise.resolve({ tracks: [] });
|
||||
const prejoinVisible = isPrejoinPageVisible(getState());
|
||||
|
||||
logger.debug(`On connection established: prejoinVisible: ${prejoinVisible}, initialGUMPromiseExists=${
|
||||
Boolean(initialGUMPromise)}, promiseExists=${Boolean(promise)}`);
|
||||
|
||||
if (prejoinVisible) {
|
||||
promise.then(() => {
|
||||
const state = getState();
|
||||
let localTracks = getLocalTracks(state['features/base/tracks']);
|
||||
const trackReplacePromises = [];
|
||||
|
||||
// Do not signal audio/video tracks if the user joins muted.
|
||||
for (const track of localTracks) {
|
||||
// Always add the audio track on Safari because of a known issue where audio playout doesn't happen
|
||||
// if the user joins audio and video muted.
|
||||
if ((track.muted && !(browser.isWebKitBased() && track.jitsiTrack
|
||||
&& track.jitsiTrack.getType() === MEDIA_TYPE.AUDIO)) || iAmVisitor(state)) {
|
||||
trackReplacePromises.push(dispatch(replaceLocalTrack(track.jitsiTrack, null))
|
||||
.catch((error: any) => {
|
||||
logger.error(`Failed to replace local track (${track.jitsiTrack}) with null: ${error}`);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Promise.allSettled(trackReplacePromises).then(() => {
|
||||
|
||||
// Re-fetch the local tracks after muted tracks have been removed above.
|
||||
// This is needed, because the tracks are effectively disposed by the replaceLocalTrack and should
|
||||
// not be used anymore.
|
||||
localTracks = getLocalTracks(getState()['features/base/tracks']);
|
||||
|
||||
const jitsiTracks = localTracks.map((t: any) => t.jitsiTrack);
|
||||
|
||||
|
||||
return APP.conference.startConference(jitsiTracks);
|
||||
})
|
||||
.catch(logger.error);
|
||||
});
|
||||
} else {
|
||||
promise.then(({ tracks }) => {
|
||||
let tracksToUse = tracks ?? [];
|
||||
|
||||
if (iAmVisitor(getState())) {
|
||||
tracksToUse = [];
|
||||
tracks.forEach(track => track.dispose().catch(logger.error));
|
||||
dispatch(gumPending([ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ], IGUMPendingState.NONE));
|
||||
}
|
||||
|
||||
dispatch(setInitialGUMPromise());
|
||||
|
||||
return APP.conference.startConference(tracksToUse);
|
||||
})
|
||||
.catch(logger.error);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
});
|
||||
704
react/features/base/conference/reducer.ts
Normal file
704
react/features/base/conference/reducer.ts
Normal file
@@ -0,0 +1,704 @@
|
||||
import { AnyAction } from 'redux';
|
||||
|
||||
import { FaceLandmarks } from '../../face-landmarks/types';
|
||||
import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock/constants';
|
||||
import { ISpeakerStats } from '../../speaker-stats/reducer';
|
||||
import { SET_CONFIG } from '../config/actionTypes';
|
||||
import { IConfig } from '../config/configType';
|
||||
import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection/actionTypes';
|
||||
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
import { assign, equals, set } from '../redux/functions';
|
||||
|
||||
import {
|
||||
AUTH_STATUS_CHANGED,
|
||||
CONFERENCE_FAILED,
|
||||
CONFERENCE_JOINED,
|
||||
CONFERENCE_LEFT,
|
||||
CONFERENCE_LOCAL_SUBJECT_CHANGED,
|
||||
CONFERENCE_PROPERTIES_CHANGED,
|
||||
CONFERENCE_SUBJECT_CHANGED,
|
||||
CONFERENCE_TIMESTAMP_CHANGED,
|
||||
CONFERENCE_WILL_JOIN,
|
||||
CONFERENCE_WILL_LEAVE,
|
||||
DATA_CHANNEL_CLOSED,
|
||||
DATA_CHANNEL_OPENED,
|
||||
LOCK_STATE_CHANGED,
|
||||
P2P_STATUS_CHANGED,
|
||||
SET_ASSUMED_BANDWIDTH_BPS,
|
||||
SET_FOLLOW_ME,
|
||||
SET_FOLLOW_ME_RECORDER,
|
||||
SET_OBFUSCATED_ROOM,
|
||||
SET_PASSWORD,
|
||||
SET_PENDING_SUBJECT_CHANGE,
|
||||
SET_ROOM,
|
||||
SET_START_MUTED_POLICY,
|
||||
SET_START_REACTIONS_MUTED,
|
||||
UPDATE_CONFERENCE_METADATA
|
||||
} from './actionTypes';
|
||||
import { isRoomValid } from './functions';
|
||||
|
||||
const DEFAULT_STATE = {
|
||||
assumedBandwidthBps: undefined,
|
||||
conference: undefined,
|
||||
dataChannelOpen: undefined,
|
||||
e2eeSupported: undefined,
|
||||
joining: undefined,
|
||||
leaving: undefined,
|
||||
locked: undefined,
|
||||
membersOnly: undefined,
|
||||
metadata: undefined,
|
||||
password: undefined,
|
||||
passwordRequired: undefined,
|
||||
properties: undefined
|
||||
};
|
||||
|
||||
export interface IConferenceMetadata {
|
||||
files: {
|
||||
[fileId: string]: {
|
||||
authorParticipantJid: string;
|
||||
authorParticipantName: string;
|
||||
conferenceFullName: string;
|
||||
fileId: string;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
fileType: string;
|
||||
progress?: number;
|
||||
timestamp: number;
|
||||
};
|
||||
};
|
||||
recording?: {
|
||||
isTranscribingEnabled: boolean;
|
||||
};
|
||||
visitors?: {
|
||||
live: boolean;
|
||||
};
|
||||
whiteboard?: {
|
||||
collabDetails: {
|
||||
roomId: string;
|
||||
roomKey: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface IJitsiConference {
|
||||
addCommandListener: Function;
|
||||
addLobbyMessageListener: Function;
|
||||
addTrack: Function;
|
||||
authenticateAndUpgradeRole: Function;
|
||||
avModerationApprove: Function;
|
||||
avModerationReject: Function;
|
||||
callUUID?: string;
|
||||
createVideoSIPGWSession: Function;
|
||||
dial: Function;
|
||||
disableAVModeration: Function;
|
||||
disableLobby: Function;
|
||||
enableAVModeration: Function;
|
||||
enableLobby: Function;
|
||||
end: Function;
|
||||
getBreakoutRooms: Function;
|
||||
getConnection: Function;
|
||||
getFileSharing: Function;
|
||||
getLocalParticipantProperty: Function;
|
||||
getLocalTracks: Function;
|
||||
getMeetingUniqueId: Function;
|
||||
getMetadataHandler: Function;
|
||||
getName: Function;
|
||||
getParticipantById: Function;
|
||||
getParticipantCount: Function;
|
||||
getParticipants: Function;
|
||||
getRole: Function;
|
||||
getShortTermCredentials: Function;
|
||||
getSpeakerStats: () => ISpeakerStats;
|
||||
getSsrcByTrack: Function;
|
||||
getTranscriptionStatus: Function;
|
||||
grantOwner: Function;
|
||||
isAVModerationSupported: Function;
|
||||
isE2EEEnabled: Function;
|
||||
isE2EESupported: Function;
|
||||
isEndConferenceSupported: Function;
|
||||
isLobbySupported: Function;
|
||||
isP2PActive: Function;
|
||||
isSIPCallingSupported: Function;
|
||||
join: Function;
|
||||
joinLobby: Function;
|
||||
kickParticipant: Function;
|
||||
leave: Function;
|
||||
lobbyApproveAccess: Function;
|
||||
lobbyDenyAccess: Function;
|
||||
lock: Function;
|
||||
markParticipantVerified: Function;
|
||||
muteParticipant: Function;
|
||||
myLobbyUserId: Function;
|
||||
myUserId: Function;
|
||||
off: Function;
|
||||
on: Function;
|
||||
options: any;
|
||||
removeTrack: Function;
|
||||
replaceTrack: Function;
|
||||
room: IJitsiConferenceRoom;
|
||||
sendApplicationLog: Function;
|
||||
sendCommand: Function;
|
||||
sendCommandOnce: Function;
|
||||
sendEndpointMessage: Function;
|
||||
sendFaceLandmarks: (faceLandmarks: FaceLandmarks) => void;
|
||||
sendFeedback: Function;
|
||||
sendLobbyMessage: Function;
|
||||
sendMessage: Function;
|
||||
sendPrivateTextMessage: Function;
|
||||
sendReaction: Function;
|
||||
sendTextMessage: Function;
|
||||
sendTones: Function;
|
||||
sessionId: string;
|
||||
setAssumedBandwidthBps: (value: number) => void;
|
||||
setDesktopSharingFrameRate: Function;
|
||||
setDisplayName: Function;
|
||||
setIsSilent: Function;
|
||||
setLocalParticipantProperty: Function;
|
||||
setMediaEncryptionKey: Function;
|
||||
setReceiverConstraints: Function;
|
||||
setSenderVideoConstraint: Function;
|
||||
setStartMutedPolicy: Function;
|
||||
setSubject: Function;
|
||||
setTranscriptionLanguage: Function;
|
||||
startRecording: Function;
|
||||
startVerification: Function;
|
||||
stopRecording: Function;
|
||||
toggleE2EE: Function;
|
||||
}
|
||||
|
||||
export interface IConferenceState {
|
||||
assumedBandwidthBps?: number;
|
||||
authEnabled?: boolean;
|
||||
authLogin?: string;
|
||||
authRequired?: IJitsiConference;
|
||||
conference?: IJitsiConference;
|
||||
conferenceTimestamp?: number;
|
||||
dataChannelOpen?: boolean;
|
||||
e2eeSupported?: boolean;
|
||||
error?: Error;
|
||||
followMeEnabled?: boolean;
|
||||
followMeRecorderEnabled?: boolean;
|
||||
joining?: IJitsiConference;
|
||||
leaving?: IJitsiConference;
|
||||
lobbyError?: boolean;
|
||||
lobbyWaitingForHost?: boolean;
|
||||
localSubject?: string;
|
||||
locked?: string;
|
||||
membersOnly?: IJitsiConference;
|
||||
metadata?: IConferenceMetadata;
|
||||
obfuscatedRoom?: string;
|
||||
obfuscatedRoomSource?: string;
|
||||
p2p?: Object;
|
||||
password?: string;
|
||||
passwordRequired?: IJitsiConference;
|
||||
pendingSubjectChange?: string;
|
||||
properties?: object;
|
||||
room?: string;
|
||||
startAudioMutedPolicy?: boolean;
|
||||
startReactionsMuted?: boolean;
|
||||
startVideoMutedPolicy?: boolean;
|
||||
subject?: string;
|
||||
}
|
||||
|
||||
export interface IJitsiConferenceRoom {
|
||||
locked: boolean;
|
||||
myroomjid: string;
|
||||
roomjid: string;
|
||||
xmpp: {
|
||||
moderator: {
|
||||
logout: Function;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface IConferenceFailedError extends Error {
|
||||
params: Array<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for actions that contain the conference object, so that it can be
|
||||
* stored for use by other action creators.
|
||||
*/
|
||||
ReducerRegistry.register<IConferenceState>('features/base/conference',
|
||||
(state = DEFAULT_STATE, action): IConferenceState => {
|
||||
switch (action.type) {
|
||||
case AUTH_STATUS_CHANGED:
|
||||
return _authStatusChanged(state, action);
|
||||
|
||||
case CONFERENCE_FAILED:
|
||||
return _conferenceFailed(state, action);
|
||||
|
||||
case CONFERENCE_JOINED:
|
||||
return _conferenceJoined(state, action);
|
||||
|
||||
case CONFERENCE_SUBJECT_CHANGED:
|
||||
return set(state, 'subject', action.subject);
|
||||
|
||||
case CONFERENCE_LOCAL_SUBJECT_CHANGED:
|
||||
return set(state, 'localSubject', action.localSubject);
|
||||
|
||||
case CONFERENCE_PROPERTIES_CHANGED:
|
||||
return _conferencePropertiesChanged(state, action);
|
||||
|
||||
case CONFERENCE_TIMESTAMP_CHANGED:
|
||||
return set(state, 'conferenceTimestamp', action.conferenceTimestamp);
|
||||
|
||||
case CONFERENCE_LEFT:
|
||||
case CONFERENCE_WILL_LEAVE:
|
||||
return _conferenceLeftOrWillLeave(state, action);
|
||||
|
||||
case CONFERENCE_WILL_JOIN:
|
||||
return _conferenceWillJoin(state, action);
|
||||
|
||||
case CONNECTION_WILL_CONNECT:
|
||||
return set(state, 'authRequired', undefined);
|
||||
|
||||
case DATA_CHANNEL_CLOSED:
|
||||
return set(state, 'dataChannelOpen', false);
|
||||
|
||||
case DATA_CHANNEL_OPENED:
|
||||
return set(state, 'dataChannelOpen', true);
|
||||
|
||||
case LOCK_STATE_CHANGED:
|
||||
return _lockStateChanged(state, action);
|
||||
|
||||
case P2P_STATUS_CHANGED:
|
||||
return _p2pStatusChanged(state, action);
|
||||
|
||||
case SET_ASSUMED_BANDWIDTH_BPS: {
|
||||
const assumedBandwidthBps = action.assumedBandwidthBps >= 0
|
||||
? Number(action.assumedBandwidthBps)
|
||||
: undefined;
|
||||
|
||||
return set(state, 'assumedBandwidthBps', assumedBandwidthBps);
|
||||
}
|
||||
case SET_FOLLOW_ME:
|
||||
return set(state, 'followMeEnabled', action.enabled);
|
||||
|
||||
case SET_FOLLOW_ME_RECORDER:
|
||||
return { ...state,
|
||||
followMeRecorderEnabled: action.enabled,
|
||||
followMeEnabled: action.enabled
|
||||
};
|
||||
|
||||
case SET_START_REACTIONS_MUTED:
|
||||
return set(state, 'startReactionsMuted', action.muted);
|
||||
|
||||
case SET_LOCATION_URL:
|
||||
return set(state, 'room', undefined);
|
||||
|
||||
case SET_OBFUSCATED_ROOM:
|
||||
return { ...state,
|
||||
obfuscatedRoom: action.obfuscatedRoom,
|
||||
obfuscatedRoomSource: action.obfuscatedRoomSource
|
||||
};
|
||||
|
||||
case SET_PASSWORD:
|
||||
return _setPassword(state, action);
|
||||
|
||||
case SET_PENDING_SUBJECT_CHANGE:
|
||||
return set(state, 'pendingSubjectChange', action.subject);
|
||||
|
||||
case SET_ROOM:
|
||||
return _setRoom(state, action);
|
||||
|
||||
case SET_START_MUTED_POLICY:
|
||||
return {
|
||||
...state,
|
||||
startAudioMutedPolicy: action.startAudioMutedPolicy,
|
||||
startVideoMutedPolicy: action.startVideoMutedPolicy
|
||||
};
|
||||
|
||||
case UPDATE_CONFERENCE_METADATA:
|
||||
return {
|
||||
...state,
|
||||
metadata: action.metadata
|
||||
};
|
||||
|
||||
case SET_CONFIG:
|
||||
return _setConfig(state, action);
|
||||
}
|
||||
|
||||
return state;
|
||||
});
|
||||
|
||||
/**
|
||||
* Processes subject and local subject of the conference based on the new config.
|
||||
*
|
||||
* @param {Object} state - The Redux state of feature base/conference.
|
||||
* @param {Action} action - The Redux action SET_CONFIG to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state after the reduction of the specified action.
|
||||
*/
|
||||
function _setConfig(state: IConferenceState, { config }: { config: IConfig; }) {
|
||||
const { localSubject, subject } = config;
|
||||
|
||||
return {
|
||||
...state,
|
||||
localSubject,
|
||||
pendingSubjectChange: subject,
|
||||
subject: undefined
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action AUTH_STATUS_CHANGED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action AUTH_STATUS_CHANGED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _authStatusChanged(state: IConferenceState,
|
||||
{ authEnabled, authLogin }: { authEnabled: boolean; authLogin: string; }) {
|
||||
return assign(state, {
|
||||
authEnabled,
|
||||
authLogin
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action CONFERENCE_FAILED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _conferenceFailed(state: IConferenceState, { conference, error }: {
|
||||
conference: IJitsiConference; error: IConferenceFailedError; }) {
|
||||
// The current (similar to getCurrentConference in
|
||||
// base/conference/functions.any.js) conference which is joining or joined:
|
||||
const conference_ = state.conference || state.joining;
|
||||
|
||||
if (conference_ && conference_ !== conference) {
|
||||
return state;
|
||||
}
|
||||
|
||||
let authRequired;
|
||||
let membersOnly;
|
||||
let passwordRequired;
|
||||
let lobbyWaitingForHost;
|
||||
let lobbyError;
|
||||
|
||||
switch (error.name) {
|
||||
case JitsiConferenceErrors.AUTHENTICATION_REQUIRED:
|
||||
authRequired = conference;
|
||||
break;
|
||||
|
||||
/**
|
||||
* Access denied while waiting in the lobby.
|
||||
* A conference error when we tried to join into a room with no display name when lobby is enabled in the room.
|
||||
*/
|
||||
case JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED:
|
||||
case JitsiConferenceErrors.DISPLAY_NAME_REQUIRED: {
|
||||
lobbyError = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case JitsiConferenceErrors.MEMBERS_ONLY_ERROR: {
|
||||
membersOnly = conference;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [ _lobbyJid, _lobbyWaitingForHost ] = error.params;
|
||||
|
||||
lobbyWaitingForHost = _lobbyWaitingForHost;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case JitsiConferenceErrors.PASSWORD_REQUIRED:
|
||||
passwordRequired = conference;
|
||||
break;
|
||||
}
|
||||
|
||||
return assign(state, {
|
||||
authRequired,
|
||||
conference: undefined,
|
||||
e2eeSupported: undefined,
|
||||
error,
|
||||
joining: undefined,
|
||||
leaving: undefined,
|
||||
lobbyError,
|
||||
lobbyWaitingForHost,
|
||||
|
||||
/**
|
||||
* The indicator of how the conference/room is locked. If falsy, the
|
||||
* conference/room is unlocked; otherwise, it's either
|
||||
* {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
locked: passwordRequired ? LOCKED_REMOTELY : undefined,
|
||||
membersOnly,
|
||||
password: undefined,
|
||||
|
||||
/**
|
||||
* The JitsiConference instance which requires a password to join.
|
||||
*
|
||||
* @type {JitsiConference}
|
||||
*/
|
||||
passwordRequired
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action CONFERENCE_JOINED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _conferenceJoined(state: IConferenceState, { conference }: { conference: IJitsiConference; }) {
|
||||
// FIXME The indicator which determines whether a JitsiConference is locked
|
||||
// i.e. password-protected is private to lib-jitsi-meet. However, the
|
||||
// library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
|
||||
// with a password.
|
||||
// FIXME Technically JitsiConference.room is a private field.
|
||||
const locked = conference.room?.locked ? LOCKED_REMOTELY : undefined;
|
||||
|
||||
return assign(state, {
|
||||
authRequired: undefined,
|
||||
|
||||
/**
|
||||
* The JitsiConference instance represented by the Redux state of the
|
||||
* feature base/conference.
|
||||
*
|
||||
* @type {JitsiConference}
|
||||
*/
|
||||
conference,
|
||||
|
||||
e2eeSupported: conference.isE2EESupported(),
|
||||
|
||||
joining: undefined,
|
||||
membersOnly: undefined,
|
||||
leaving: undefined,
|
||||
|
||||
lobbyError: undefined,
|
||||
lobbyWaitingForHost: undefined,
|
||||
|
||||
/**
|
||||
* The indicator which determines whether the conference is locked.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
locked,
|
||||
passwordRequired: undefined
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific redux action {@link CONFERENCE_LEFT} or
|
||||
* {@link CONFERENCE_WILL_LEAVE} for the feature base/conference.
|
||||
*
|
||||
* @param {Object} state - The redux state of the feature base/conference.
|
||||
* @param {Action} action - The redux action {@code CONFERENCE_LEFT} or
|
||||
* {@code CONFERENCE_WILL_LEAVE} to reduce.
|
||||
* @private
|
||||
* @returns {Object} The next/new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _conferenceLeftOrWillLeave(state: IConferenceState, { conference, type }:
|
||||
{ conference: IJitsiConference; type: string; }) {
|
||||
const nextState = { ...state };
|
||||
|
||||
// The redux action CONFERENCE_LEFT is the last time that we should be
|
||||
// hearing from a JitsiConference instance.
|
||||
//
|
||||
// The redux action CONFERENCE_WILL_LEAVE represents the order of the user
|
||||
// to leave a JitsiConference instance. From the user's perspective, there's
|
||||
// no going back (with respect to the instance itself). The app will perform
|
||||
// due clean-up like leaving the associated room, but the instance is no
|
||||
// longer the focus of the attention of the user and, consequently, the app.
|
||||
for (const p in state) {
|
||||
if (state[p as keyof IConferenceState] === conference) {
|
||||
nextState[p as keyof IConferenceState] = undefined;
|
||||
|
||||
switch (p) {
|
||||
case 'conference':
|
||||
case 'passwordRequired':
|
||||
// XXX Clear/unset locked & password for a conference which has
|
||||
// been LOCKED_LOCALLY or LOCKED_REMOTELY.
|
||||
delete nextState.locked;
|
||||
delete nextState.password;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type === CONFERENCE_WILL_LEAVE) {
|
||||
// A CONFERENCE_WILL_LEAVE is of further consequence only if it is
|
||||
// expected i.e. if the specified conference is joining or joined.
|
||||
if (conference === state.joining || conference === state.conference) {
|
||||
/**
|
||||
* The JitsiConference instance which is currently in the process of
|
||||
* being left.
|
||||
*
|
||||
* @type {JitsiConference}
|
||||
*/
|
||||
nextState.leaving = conference;
|
||||
}
|
||||
}
|
||||
|
||||
return nextState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action CONFERENCE_PROPERTIES_CHANGED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action CONFERENCE_PROPERTIES_CHANGED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _conferencePropertiesChanged(state: IConferenceState, { properties }: { properties: Object; }) {
|
||||
if (!equals(state.properties, properties)) {
|
||||
return assign(state, {
|
||||
properties
|
||||
});
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _conferenceWillJoin(state: IConferenceState, { conference }: { conference: IJitsiConference; }) {
|
||||
return assign(state, {
|
||||
error: undefined,
|
||||
joining: conference
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _lockStateChanged(state: IConferenceState, { conference, locked }: { conference: Object; locked: boolean; }) {
|
||||
if (state.conference !== conference) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return assign(state, {
|
||||
locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
|
||||
password: locked ? state.password : undefined
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
|
||||
* base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _p2pStatusChanged(state: IConferenceState, action: AnyAction) {
|
||||
return set(state, 'p2p', action.p2p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action SET_PASSWORD to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _setPassword(state: IConferenceState, { conference, method, password }: {
|
||||
conference: IJitsiConference; method: Object; password: string; }) {
|
||||
switch (method) {
|
||||
case conference.join:
|
||||
return assign(state, {
|
||||
// 1. The JitsiConference which transitions away from
|
||||
// passwordRequired MUST remain in the redux state
|
||||
// features/base/conference until it transitions into
|
||||
// conference; otherwise, there is a span of time during which
|
||||
// the redux state does not even know that there is a
|
||||
// JitsiConference whatsoever.
|
||||
//
|
||||
// 2. The redux action setPassword will attempt to join the
|
||||
// JitsiConference so joining is an appropriate transitional
|
||||
// redux state.
|
||||
//
|
||||
// 3. The redux action setPassword will perform the same check
|
||||
// before it proceeds with the re-join.
|
||||
joining: state.conference ? state.joining : conference,
|
||||
locked: LOCKED_REMOTELY,
|
||||
|
||||
/**
|
||||
* The password with which the conference is to be joined.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
password
|
||||
});
|
||||
|
||||
case conference.lock:
|
||||
return assign(state, {
|
||||
locked: password ? LOCKED_LOCALLY : undefined,
|
||||
password
|
||||
});
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action SET_ROOM of the feature base/conference.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/conference.
|
||||
* @param {Action} action - The Redux action SET_ROOM to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/conference after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _setRoom(state: IConferenceState, action: AnyAction) {
|
||||
let { room } = action;
|
||||
|
||||
if (!isRoomValid(room)) {
|
||||
// Technically, there are multiple values which don't represent valid
|
||||
// room names. Practically, each of them is as bad as the rest of them
|
||||
// because we can't use any of them to join a conference.
|
||||
room = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the room of the conference (to be) joined.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
return assign(state, {
|
||||
error: undefined,
|
||||
room
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user