Skip to content

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

test(iframe): add specs for toggleAudio and toggleVideo commands and events

ravindra-RKBb53fae09d5d8
diff --git a/tests/specs/iframe/muteSelf.spec.ts b/tests/specs/iframe/muteSelf.spec.ts
index e460ecfecd..b40f8b0b8d 100644
--- a/tests/specs/iframe/muteSelf.spec.ts
+++ b/tests/specs/iframe/muteSelf.spec.ts
@@ -11,9 +11,81 @@ setTestProperties(__filename, {
usesBrowsers: [ 'p1' ]
});
-describe('muteRemoteParticipant iframe API command on the local participant', () => {
+describe('Local participant mute iframe API commands', () => {
let p1: Participant;
+ /**
+ * Executes a media toggle command, waits for its event, and verifies that the corresponding
+ * getter reflects the expected mute state. Also verifies the toolbar button state inside
+ * the meeting iframe to confirm the actual track state changed.
+ *
+ * @param command The iframe API toggle command name ('toggleAudio' | 'toggleVideo').
+ * @param event The iframe API event name ('audioMuteStatusChanged' | 'videoMuteStatusChanged').
+ * @param getter The iframe API getter function returning whether media is muted.
+ * @param expectedMuted Whether the media is expected to be muted.
+ */
+ async function toggleAndExpect(
+ command: 'toggleAudio' | 'toggleVideo',
+ event: 'audioMuteStatusChanged' | 'videoMuteStatusChanged',
+ getter: () => Promise<boolean>,
+ expectedMuted: boolean
+ ) {
+ const iframeAPI = p1.getIframeAPI();
+
+ await iframeAPI.clearEventResults(event);
+ await iframeAPI.executeCommand(command);
+
+ const statusEvent = await iframeAPI.waitForEventResult<{ muted: boolean; }>(
+ event,
+ `${event} event was not received for ${command} (${expectedMuted ? 'mute' : 'unmute'})`
+ );
+
+ expect(statusEvent.muted).toBe(expectedMuted);
+
+ await p1.driver.waitUntil(
+ async () => (await getter()) === expectedMuted,
+ {
+ timeout: 5000,
+ timeoutMsg: `${command} getter did not reflect muted state ${expectedMuted}`
+ }
+ );
+
+ // Verify UI toolbar button reflects the mute state (must run inside the meeting iframe).
+ await p1.switchToIFrame();
+
+ try {
+ const toolbar = p1.getToolbar();
+
+ if (command === 'toggleAudio') {
+ if (expectedMuted) {
+ await toolbar.audioUnMuteBtn.waitForExist({
+ timeout: 2000,
+ timeoutMsg: 'Audio unmute button not found after mute'
+ });
+ } else {
+ await toolbar.audioMuteBtn.waitForExist({
+ timeout: 2000,
+ timeoutMsg: 'Audio mute button not found after unmute'
+ });
+ }
+ } else if (command === 'toggleVideo') {
+ if (expectedMuted) {
+ await toolbar.videoUnMuteBtn.waitForExist({
+ timeout: 2000,
+ timeoutMsg: 'Video unmute button not found after mute'
+ });
+ } else {
+ await toolbar.videoMuteBtn.waitForExist({
+ timeout: 2000,
+ timeoutMsg: 'Video mute button not found after unmute'
+ });
+ }
+ }
+ } finally {
+ await p1.switchToMainFrame();
+ }
+ }
+
it('setup', async () => {
p1 = await joinMuc({ name: 'p1', iFrameApi: true, token: testsConfig.jwt.preconfiguredToken });
@@ -34,12 +106,9 @@ describe('muteRemoteParticipant iframe API command on the local participant', ()
await iframeAPI.clearEventResults('audioMuteStatusChanged');
await iframeAPI.executeCommand('muteRemoteParticipant', p1EndpointId, 'audio');
- const mutedEvent: { muted: boolean; } = await p1.driver.waitUntil(
- () => iframeAPI.getEventResult('audioMuteStatusChanged'),
- {
- timeout: 5000,
- timeoutMsg: 'audioMuteStatusChanged event was not received after muteRemoteParticipant'
- }
+ const mutedEvent = await iframeAPI.waitForEventResult<{ muted: boolean; }>(
+ 'audioMuteStatusChanged',
+ 'audioMuteStatusChanged event was not received after muteRemoteParticipant'
);
expect(mutedEvent.muted).toBe(true);
@@ -52,7 +121,14 @@ describe('muteRemoteParticipant iframe API command on the local participant', ()
const secondEvent = await iframeAPI.getEventResult('audioMuteStatusChanged');
expect(secondEvent ? secondEvent.muted : true).toBe(true);
- expect(await iframeAPI.isAudioMuted()).toBe(true);
+
+ await p1.driver.waitUntil(
+ async () => await iframeAPI.isAudioMuted(),
+ {
+ timeout: 5000,
+ timeoutMsg: 'isAudioMuted() is false after muteRemoteParticipant'
+ }
+ );
});
it('mutes local video and keeps it muted when repeated', async () => {
@@ -62,12 +138,9 @@ describe('muteRemoteParticipant iframe API command on the local participant', ()
await iframeAPI.clearEventResults('videoMuteStatusChanged');
await iframeAPI.executeCommand('muteRemoteParticipant', p1EndpointId, 'video');
- const mutedEvent: { muted: boolean; } = await p1.driver.waitUntil(
- () => iframeAPI.getEventResult('videoMuteStatusChanged'),
- {
- timeout: 5000,
- timeoutMsg: 'videoMuteStatusChanged event was not received after muteRemoteParticipant'
- }
+ const mutedEvent = await iframeAPI.waitForEventResult<{ muted: boolean; }>(
+ 'videoMuteStatusChanged',
+ 'videoMuteStatusChanged event was not received after muteRemoteParticipant'
);
expect(mutedEvent.muted).toBe(true);
@@ -80,6 +153,57 @@ describe('muteRemoteParticipant iframe API command on the local participant', ()
const secondEvent = await iframeAPI.getEventResult('videoMuteStatusChanged');
expect(secondEvent ? secondEvent.muted : true).toBe(true);
- expect(await iframeAPI.isVideoMuted()).toBe(true);
+
+ await p1.driver.waitUntil(
+ async () => await iframeAPI.isVideoMuted(),
+ {
+ timeout: 5000,
+ timeoutMsg: 'isVideoMuted() is false after muteRemoteParticipant'
+ }
+ );
+ });
+
+ it('toggles audio mute status via toggleAudio command', async () => {
+ const iframeAPI = p1.getIframeAPI();
+
+ // Ensure audio is muted initially so the test is self-contained.
+ if (!await iframeAPI.isAudioMuted()) {
+ await iframeAPI.executeCommand('muteRemoteParticipant', await p1.getEndpointId(), 'audio');
+ await p1.driver.waitUntil(
+ async () => await iframeAPI.isAudioMuted(),
+ {
+ timeout: 5000,
+ timeoutMsg: 'Initial audio mute setup failed'
+ }
+ );
+ }
+
+ // Toggle to unmute.
+ await toggleAndExpect('toggleAudio', 'audioMuteStatusChanged', () => iframeAPI.isAudioMuted(), false);
+
+ // Toggle to mute again.
+ await toggleAndExpect('toggleAudio', 'audioMuteStatusChanged', () => iframeAPI.isAudioMuted(), true);
+ });
+
+ it('toggles video mute status via toggleVideo command', async () => {
+ const iframeAPI = p1.getIframeAPI();
+
+ // Ensure video is muted initially so the test is self-contained.
+ if (!await iframeAPI.isVideoMuted()) {
+ await iframeAPI.executeCommand('muteRemoteParticipant', await p1.getEndpointId(), 'video');
+ await p1.driver.waitUntil(
+ async () => await iframeAPI.isVideoMuted(),
+ {
+ timeout: 5000,
+ timeoutMsg: 'Initial video mute setup failed'
+ }
+ );
+ }
+
+ // Toggle to unmute.
+ await toggleAndExpect('toggleVideo', 'videoMuteStatusChanged', () => iframeAPI.isVideoMuted(), false);
+
+ // Toggle to mute again.
+ await toggleAndExpect('toggleVideo', 'videoMuteStatusChanged', () => iframeAPI.isVideoMuted(), true);
});
});