Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(lobby): allow toggleLobby without target state, add isLobbyEnabled and lobbyModeChanged event (#17784) (#17860)

Muskan Kumarid04547e3e1a2
diff --git a/modules/API/API.js b/modules/API/API.js
index 1ec51b1c7b..effdd7cf1a 100755
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -99,6 +99,7 @@ import {
resizeLargeVideo
} from '../../react/features/large-video/actions.web';
import { answerKnockingParticipant, toggleLobbyMode } from '../../react/features/lobby/actions';
+import { getLobbyEnabled } from '../../react/features/lobby/functions';
import { setSecondScreen } from '../../react/features/multi-screen/actions.web';
import { setNoiseSuppressionEnabled } from '../../react/features/noise-suppression/actions';
import { hideNotification, showNotification } from '../../react/features/notifications/actions';
@@ -278,8 +279,8 @@ function initCommands() {
APP.store.dispatch(muteRemote(participantId, muteMediaType));
},
- 'toggle-lobby': isLobbyEnabled => {
- APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
+ 'toggle-lobby': enabled => {
+ APP.store.dispatch(toggleLobbyMode(enabled));
},
'password': password => {
const { conference, passwordRequired }
@@ -1149,6 +1150,9 @@ function initCommands() {
case 'is-sharing-screen':
callback(Boolean(APP.conference.isSharingScreen));
break;
+ case 'is-lobby-enabled':
+ callback(Boolean(getLobbyEnabled(APP.store.getState())));
+ break;
case 'is-start-silent':
callback(Boolean(APP.store.getState()['features/base/config'].startSilent));
break;
@@ -1505,6 +1509,19 @@ class API {
});
}
+ /**
+ * Notify the external application that the lobby mode status has changed.
+ *
+ * @param {boolean} enabled - Whether or not lobby mode is enabled.
+ * @returns {void}
+ */
+ notifyLobbyModeChanged(enabled) {
+ this._sendEvent({
+ name: 'lobby-mode-changed',
+ enabled
+ });
+ }
+
/**
* Notify the external application that a participant was approved on moderation.
*
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index bb2df9fecf..60b247006e 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -147,6 +147,7 @@ const events = {
'filmstrip-display-changed': 'filmstripDisplayChanged',
'incoming-message': 'incomingMessage',
'knocking-participant': 'knockingParticipant',
+ 'lobby-mode-changed': 'lobbyModeChanged',
'log': 'log',
'mic-error': 'micError',
'moderation-participant-approved': 'moderationParticipantApproved',
@@ -1289,6 +1290,18 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
});
}
+ /**
+ * Returns the lobby mode status.
+ *
+ * @returns {Promise<boolean>} - Resolves with the lobby mode status and rejects on
+ * failure.
+ */
+ isLobbyEnabled() {
+ return this._transport.sendRequest({
+ name: 'is-lobby-enabled'
+ });
+ }
+
/**
* Returns force muted status of the given participant id for the given media type.
*
diff --git a/react/features/external-api/middleware.ts b/react/features/external-api/middleware.ts
index 2db11beda5..6cebfb0508 100644
--- a/react/features/external-api/middleware.ts
+++ b/react/features/external-api/middleware.ts
@@ -29,6 +29,7 @@ import { getBaseUrl } from '../base/util/helpers';
import { appendSuffix } from '../display-name/functions';
import { SUBMIT_FEEDBACK_ERROR, SUBMIT_FEEDBACK_SUCCESS } from '../feedback/actionTypes';
import { SET_FILMSTRIP_VISIBLE } from '../filmstrip/actionTypes';
+import { SET_LOBBY_MODE_ENABLED } from '../lobby/actionTypes';
import { iAmVisitor } from '../visitors/functions';
import './subscriber';
@@ -257,6 +258,10 @@ MiddlewareRegistry.register(store => next => action => {
APP.API.notifyFilmstripDisplayChanged(action.visible);
break;
+ case SET_LOBBY_MODE_ENABLED:
+ APP.API.notifyLobbyModeChanged(action.enabled);
+ break;
+
case SUBMIT_FEEDBACK_ERROR:
APP.API.notifyFeedbackSubmitted(action.error || 'Unknown error');
break;
diff --git a/react/features/lobby/actions.any.ts b/react/features/lobby/actions.any.ts
index 214f5a1d08..c6c8c55aa5 100644
--- a/react/features/lobby/actions.any.ts
+++ b/react/features/lobby/actions.any.ts
@@ -238,15 +238,19 @@ export function startKnocking() {
/**
* Action to toggle lobby mode on or off.
*
- * @param {boolean} enabled - The desired (new) state of the lobby mode.
+ * @param {boolean} [enabled] - The desired (new) state of the lobby mode. If undefined, toggles the current state.
* @returns {Function}
*/
-export function toggleLobbyMode(enabled: boolean) {
+export function toggleLobbyMode(enabled?: boolean) {
return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
- const conference = getCurrentConference(getState);
+ const state = getState();
+ const conference = getCurrentConference(state);
+ const shouldEnable = typeof enabled === 'undefined'
+ ? !getLobbyEnabled(state)
+ : enabled;
- if (enabled) {
- if (isEnablingLobbyAllowed(getState())) {
+ if (shouldEnable) {
+ if (isEnablingLobbyAllowed(state)) {
conference?.enableLobby();
} else {
logger.info('Ignoring enable lobby request because there are visitors in the call already.');
diff --git a/react/features/lobby/reducer.ts b/react/features/lobby/reducer.ts
index 7cabb6a118..d04ca0837b 100644
--- a/react/features/lobby/reducer.ts
+++ b/react/features/lobby/reducer.ts
@@ -73,6 +73,7 @@ ReducerRegistry.register<ILobbyState>('features/lobby', (state = DEFAULT_STATE,
...state,
isDisplayNameRequiredError: false,
knocking: false,
+ lobbyEnabled: false,
lobbyVisible: false,
passwordJoinFailed: false,
};
diff --git a/tests/pageobjects/IframeAPI.ts b/tests/pageobjects/IframeAPI.ts
index 67910edccf..e62f2e2891 100644
--- a/tests/pageobjects/IframeAPI.ts
+++ b/tests/pageobjects/IframeAPI.ts
@@ -87,6 +87,13 @@ export default class IframeAPI extends BasePageObject {
return this.participant.execute(() => window.jitsiAPI.isParticipantsPaneOpen());
}
+ /**
+ * Returns whether lobby mode is enabled for the current conference.
+ */
+ isLobbyEnabled() {
+ return this.participant.execute(() => window.jitsiAPI.isLobbyEnabled());
+ }
+
/**
* Removes the embedded Jitsi Meet conference.
*/
diff --git a/tests/specs/iframe/lobby.spec.ts b/tests/specs/iframe/lobby.spec.ts
new file mode 100644
index 0000000000..fe3da184cb
--- /dev/null
+++ b/tests/specs/iframe/lobby.spec.ts
@@ -0,0 +1,107 @@
+import { expect } from '@wdio/globals';
+
+import type { Participant } from '../../helpers/Participant';
+import { setTestProperties } from '../../helpers/TestProperties';
+import { ensureTwoParticipants } from '../../helpers/participants';
+
+import { checkIframeApi } from './util';
+
+setTestProperties(__filename, {
+ usesBrowsers: [ 'p1', 'p2' ]
+});
+
+describe('Lobby iframe API commands and events', () => {
+ let p1: Participant;
+ let p2: Participant;
+
+ it('joining the meeting', async () => {
+ await ensureTwoParticipants({}, { name: 'p1', iFrameApi: true });
+
+ p1 = ctx.p1;
+ p2 = ctx.p2;
+
+ if (!await checkIframeApi(p1)) {
+ return;
+ }
+
+ if (!await p1.execute(() => APP.conference._room.isLobbySupported())) {
+ ctx.skipSuiteTests = 'The environment does not support lobby.';
+
+ return;
+ }
+
+ await p1.switchToMainFrame();
+ await p1.getIframeAPI().addEventListener('lobbyModeChanged');
+
+ expect(await p1.getIframeAPI().isLobbyEnabled()).toBe(false);
+ });
+
+ it('enables lobby via toggleLobby(true) command', async () => {
+ await p1.getIframeAPI().clearEventResults('lobbyModeChanged');
+ await p1.getIframeAPI().executeCommand('toggleLobby', true);
+ await waitForLobbyModeChanged(p1, true);
+
+ expect(await p1.getIframeAPI().isLobbyEnabled()).toBe(true);
+ expect(await p2.getNotifications().getLobbyEnabledText()).toContain(p1.name);
+
+ await p2.getNotifications().closeLobbyEnabled();
+ });
+
+ it('toggles lobby off via toggleLobby command', async () => {
+ await p1.getIframeAPI().clearEventResults('lobbyModeChanged');
+ await p1.getIframeAPI().executeCommand('toggleLobby');
+ await waitForLobbyModeChanged(p1, false);
+
+ expect(await p1.getIframeAPI().isLobbyEnabled()).toBe(false);
+ });
+
+ it('toggles lobby back on via toggleLobby command', async () => {
+ await p1.getIframeAPI().clearEventResults('lobbyModeChanged');
+ await p1.getIframeAPI().executeCommand('toggleLobby');
+ await waitForLobbyModeChanged(p1, true);
+
+ expect(await p1.getIframeAPI().isLobbyEnabled()).toBe(true);
+ });
+
+ it('reports lobby disabled from the security dialog', async () => {
+ await p1.getIframeAPI().clearEventResults('lobbyModeChanged');
+ await p1.switchToIFrame();
+
+ const p1SecurityDialog = p1.getSecurityDialog();
+
+ await p1.getToolbar().clickSecurityButton();
+ await p1SecurityDialog.waitForDisplay();
+ await p1SecurityDialog.waitForLobbyEnabled();
+ await p1SecurityDialog.toggleLobby();
+ await p1SecurityDialog.waitForLobbyEnabled(true);
+ await p1SecurityDialog.clickCloseButton();
+
+ await p1.switchToMainFrame();
+ await waitForLobbyModeChanged(p1, false);
+
+ expect(await p1.getIframeAPI().isLobbyEnabled()).toBe(false);
+ });
+});
+
+/**
+ * Waits for the lobbyModeChanged iframe API event with the given state.
+ *
+ * @param participant The participant using the iframe API, already switched to the main frame.
+ * @param enabled The expected lobby state.
+ */
+async function waitForLobbyModeChanged(participant: Participant, enabled: boolean) {
+ // matches on the value, as the event for the initial state on join can still arrive after the listener is added
+ const event = await participant.driver.waitUntil(
+ async () => {
+ const result = await participant.getIframeAPI().getEventResult('lobbyModeChanged');
+
+ return result?.enabled === enabled && result;
+ },
+ {
+ timeout: 5000,
+ timeoutMsg: `lobbyModeChanged event was not received for enabled: ${enabled}`
+ }
+ );
+
+ expect(event).toEqual({ enabled });
+}