Skip to content

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

5.3 KB
Raw Blame
import { IRooms } from '../../react/features/breakout-rooms/types';
import { LOG_PREFIX } from '../helpers/browserLogger';

import BasePageObject from './BasePageObject';

/**
 * The Iframe API and helpers from iframeAPITest.html
 */
export default class IframeAPI extends BasePageObject {
    /**
     * Returns the json object from the iframeAPI helper.
     * @param event
     */
    getEventResult(event: string): Promise<any> {
        return this.participant.execute(
            eventName => {
                const result = window.jitsiAPI.test[eventName];

                if (!result) {
                    return false;
                }

                return result;
            }, event);
    }

    /**
     * Waits for an event result from the iframeAPI helper.
     * @param event The event name.
     * @param timeoutMsg Optional timeout message.
     * @param timeout Optional timeout in milliseconds.
     */
    waitForEventResult<T = any>(event: string, timeoutMsg?: string, timeout = 5000): Promise<T> {
        return this.participant.driver.waitUntil(
            () => this.getEventResult(event),
            {
                timeout,
                timeoutMsg: timeoutMsg || `${event} event was not received`
            }
        );
    }

    /**
     * Clears the history of an event.
     * @param event
     */
    clearEventResults(event: string) {
        return this.participant.execute(
            eventName => {
                window.jitsiAPI.test[eventName] = undefined;
            }, event);
    }

    /**
     * Adds an event listener to the iframeAPI.
     * @param eventName The event name.
     */
    addEventListener(eventName: string) {
        return this.participant.execute(
            (event, prefix) => {
                // we want to add it once as we use static .test[event] to store the last event
                if (window.jitsiAPI.listenerCount(event) > 0) {
                    return;
                }
                console.log(`${new Date().toISOString()} ${prefix}iframeAPI - Adding listener for event: ${event}`);
                window.jitsiAPI.addListener(event, evt => {
                    console.log(
                        `${new Date().toISOString()} ${prefix}iframeAPI - Received ${event} event: ${JSON.stringify(evt)}`);
                    window.jitsiAPI.test[event] = evt;
                });
            }, eventName, LOG_PREFIX);
    }

    /**
     * Returns an array of available rooms and details of it.
     */
    getRoomsInfo() {
        return this.participant.execute(() => window.jitsiAPI.getRoomsInfo());
    }

    /**
     * Returns the number of participants in the conference.
     */
    getNumberOfParticipants() {
        return this.participant.execute(() => window.jitsiAPI.getNumberOfParticipants());
    }

    /**
     * Executes command using iframeAPI.
     * @param command The command.
     * @param args The arguments.
     */
    executeCommand(command: string, ...args: any[]) {
        return this.participant.execute(
            (commandName, commandArgs) =>
                window.jitsiAPI.executeCommand(commandName, ...commandArgs)
            , command, args);
    }

    /**
     * Returns the current state of the participant's pane.
     */
    isParticipantsPaneOpen() {
        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());
    }

    /**
     * Returns whether the local participant's audio is muted.
     */
    isAudioMuted() {
        return this.participant.execute(() => window.jitsiAPI.isAudioMuted());
    }

    /**
     * Returns whether the local participant's video is muted.
     */
    isVideoMuted() {
        return this.participant.execute(() => window.jitsiAPI.isVideoMuted());
    }

    /**
     * Returns the list of breakout rooms.
     */
    listBreakoutRooms(): Promise<IRooms> {
        return this.participant.execute(() => window.jitsiAPI.listBreakoutRooms());
    }

    /**
     * Removes the embedded Jitsi Meet conference.
     */
    dispose() {
        return this.participant.execute(() => window.jitsiAPI.dispose());
    }

    /**
     * Invite the given participant to the meeting via PSTN.
     */
    invitePhone(value: string) {
        return this.participant.execute(v => window.jitsiAPI.invite([ {
            type: 'phone',
            number: v
        } ]), value);
    }

    /**
     * Invite the given participant to the meeting via sip (sip jibri).
     */
    inviteSIP(value: string) {
        return this.participant.execute(v => window.jitsiAPI.invite([ {
            type: 'sip',
            address: v
        } ]), value);
    }

    /**
     * Starts a file recording or streaming session.
     * @param options
     */
    startRecording(options: any) {
        return this.participant.execute(o => window.jitsiAPI.startRecording(o), options);
    }

    /**
     * Stop a file recording or streaming session.
     * @param mode
     */
    stopRecording(mode: string) {
        return this.participant.execute(m => window.jitsiAPI.stopRecording(m), mode);
    }

    /**
     * Returns the live-streaming url.
     */
    async getLivestreamUrl() {
        return this.participant.execute(() => window.jitsiAPI.getLivestreamUrl());
    }
}