"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebConferenceSession = void 0;
/**
 * @module
 * @name WebConferenceSession
 * @description
 * This class is used to represent a web conference session containing
 * all the relevant information to the current conference session
 */
class WebConferenceSession {
    static create(id, bubble) { return new WebConferenceSession(id, bubble); }
    constructor(id, bubble) {
        /**
         * @public
         * @name hasLocalSharing
         * @description Boolean indicating whether the current user is currently sharing his screen
         * @type {boolean}
         * @readonly
         */
        this.hasLocalSharing = false;
        /*
        * PRIVATE UCAAS PARAMETERS NOT TO BE USED BY SDK
        */
        this.type = "v2";
        this.haveJoined = false;
        this.isInExternalWindow = false;
        this.isOnlySharingWindow = false;
        this.control = {
            activeControl: false,
            hasRemoteControlling: false,
            controller: null,
            controlled: null
        };
        this.conferenceLayoutSize = {};
        this.record = {
            isRecording: false,
            recordingIsPaused: false
        };
        this.recordingStarted = false;
        this.currentRecordingState = "";
        this.isMyConference = false;
        this.dimLocalSharingScreen = false;
        this.originalVideoStream = null;
        this.id = id;
        this.bubble = bubble;
        this.duration = 0;
        this.participants = [];
        this.conferenceView = "grid_view";
        this.duration = 0;
        this.haveJoined = false;
        this.isMyConference = false;
        this.pinnedParticipant = null;
        this.locked = false;
        this.localStreams = [];
    }
    /**
     * @public
     * @function getParticipants
     * @instance
     * @description
     *    Get a list of all connected participants in the conference (except for yourself)
     * @returns {WebConferenceParticipant[]} Return an array of all WebConferenceParticipants taking part of the web conference
     */
    getParticipants() {
        return this.participants;
    }
    /**
     * @public
     * @function getLocalParticipant
     * @instance
     * @description
     *    Get yourself as a web conference participant
     * @returns {WebConferenceParticipant} Return the current user as a web conference participant connected to the conference
     */
    getLocalParticipant() {
        return this.localParticipant;
    }
    /**
     * @public
     * @function getBubble
     * @instance
     * @description
     *    Get the bubble related to the web conference session
     * @returns {Bubble} Get the bubble related to the web conference session
     */
    getBubble() {
        return this.bubble;
    }
    /**
     * @public
     * @function getAudioSession
     * @instance
     * @description
     *    Get the jingle audio session related to the conference session
     * @returns {any} The jingle audio session related to the conference session
     */
    getAudioSession() {
        return this.audioSession;
    }
    /**
     * @public
     * @function getSharingParticipant
     * @instance
     * @description
     *    Get web conference participant object that is currently sharing in the conference (could not be myself)
     * @returns {WebConferenceParticipant} Web conference participant object that is currently sharing (could not be myself)
     */
    getSharingParticipant() {
        return this.sharingParticipant;
    }
    /**
     * @public
     * @function getLocalSharingSession
     * @instance
     * @description
     *    Get the local sharing session (if any)
     * @returns {any} The local sharing session (or null)
     */
    getLocalSharingSession() {
        return this.localSharingSession;
    }
    /**
     * @public
     * @function getRemoteSharingSession
     * @instance
     * @description
     *    Get the remote sharing session (if any)
     * @returns {any} The remote sharing session (or null) from the sharing participant object
     */
    getRemoteSharingSession() {
        return (this.sharingParticipant) ? this.sharingParticipant.videoSession : null;
    }
    /**
     * @public
     * @function getParticipantById
     * @instance
     * @param {string} participantId the ID of the participant to find
     * @description
     *    Find and return a participant by his Id
     * @returns {WebConferenceParticipant} The WebConferenceParticipant (if found) by his id
     */
    getParticipantById(participantId) {
        if (this.localParticipant.id === participantId)
            return this.localParticipant;
        const participant = this.participants.find((part) => { return part.id === participantId; });
        return participant;
    }
    /**
     * @public
     * @function isLock
     * @instance
     * @description
     *    Check if the current web conference is locked. In case it's locked, no other user is allowed to join it
     * @returns {boolean} Return a boolean value indicating whether the web conference is currently locked
     */
    isLocked() {
        return this.locked;
    }
    /**
     * @public
     * @function getDelegateParticipantsList
     * @instance
     * @description
     *    Get the list of participants to whom we can delegate the current conference. Delegation means that we give
     *    the ownership of the conference to another user
     * @returns {Array} Return an array of WebConferenceParticipant to whom we can delegate the conference
     */
    getDelegateParticipantsList() {
        return this.participants.filter((participant) => {
            return participant.delegateCapability;
        });
    }
    /*
    * PRIVATE UCAAS FUNCTIONS NOT TO BE USED BY SDK
    */
    addOrUpdateParticipant(participant) {
        if (this.localParticipant.id === participant.id) {
            this.localParticipant.mute = participant.mute;
            // this.localParticipant.rxSubject.next('updateInfo');
            return;
        }
        const participantIndex = this.participants.findIndex((part) => { return part.id === participant.id; });
        if (participantIndex !== -1) {
            const existingParticipant = this.participants[participantIndex];
            existingParticipant.mute = participant.mute;
            // existingParticipant.rxSubject.next('updateInfo');
        }
        else {
            this.participants.push(participant);
        }
    }
    startDuration() {
        if (this.durationTimer)
            return;
        this.durationTimer = setInterval(() => {
            this.duration++;
        }, 1000);
    }
    stopDuration() {
        if (this.durationTimer) {
            clearInterval(this.durationTimer);
            this.durationTimer = null;
            this.duration = 0;
        }
    }
    getPinnedParticipant() {
        //check if participant is still here
        if (this.pinnedParticipant) {
            const checkPinnedParticipant = this.getParticipantByIdAndMediaType(this.pinnedParticipant.id, this.pinnedParticipant.mediaType);
            if (!checkPinnedParticipant)
                this.pinnedParticipant = null;
        }
        return this.pinnedParticipant;
    }
    updatePinnedParticipant(participant = null, mediaType = "") {
        if (!participant) {
            this.pinnedParticipant = null;
            return;
        }
        //pin participant
        this.pinnedParticipant = {
            id: participant.id,
            mediaType: mediaType
        };
    }
    setLocked(lock = false) {
        this.locked = lock;
    }
    setSharingParticipant(participant = null) {
        if (!participant && this.sharingParticipant.videoSession) {
            this.sharingParticipant.videoSession.terminate();
            this.sharingParticipant.videoSession = null;
        }
        this.sharingParticipant = participant;
    }
    getParticipantByIdAndMediaType(participantId, mediaType) {
        if (mediaType === "sharing") {
            if (this.localParticipant.id === participantId) {
                return (this.hasLocalSharing) ? this.localParticipant : null;
            }
            if (this.sharingParticipant && this.sharingParticipant.id === participantId) {
                return this.sharingParticipant;
            }
        }
        else {
            if (this.localParticipant.id === participantId) {
                return (this.localParticipant.videoSession) ? this.localParticipant : null;
            }
            const participant = this.participants.find((part) => { return part.id === participantId; });
            if (participant && participant.videoSession)
                return participant;
        }
        return null;
    }
}
exports.WebConferenceSession = WebConferenceSession;
//# sourceMappingURL=webConferenceSession.js.map