// TODO: This is a candidate to be added to the common client library import PubSub from 'pubsub-js'; import { Logger } from '../common/logger'; export class ConferenceState { private isInVideoConference = false; private _isInAudioConference = false; private _isVideoConferenceFullScreen = false; private logger = Logger.getInstance(); constructor() { this.resetState(); PubSub.subscribe('onConferenceViewState', (msg, data) => { this.processConferenceNotification(data); }); PubSub.subscribe('onChatWindowClosed', (msg, data) => { this.resetState(); }); } public get isVideoConferenceFullScreen(): boolean { return this._isVideoConferenceFullScreen; } public get isInAudioConference(): boolean { return this._isInAudioConference; } public resetState() { this.isInVideoConference = false; this._isInAudioConference = false; this._isVideoConferenceFullScreen = false; } // TODO: any public setConferenceState(stateObject: any) { if (stateObject.hasOwnProperty('isInVideoConference')) { if (stateObject.isInVideoConference !== this.isInVideoConference) { PubSub.publish('onConferenceStateChange', { isInVideoConference: stateObject.isInVideoConference }); this.isInVideoConference = stateObject.isInVideoConference; } } if (stateObject.hasOwnProperty('isVideoConferenceFullScreen')) { if (stateObject.isVideoConferenceFullScreen !== this._isVideoConferenceFullScreen) { PubSub.publish('onConferenceStateChange', { isVideoConferenceFullScreen: stateObject.isVideoConferenceFullScreen }); this._isVideoConferenceFullScreen = stateObject.isVideoConferenceFullScreen; } } if (stateObject.hasOwnProperty('isInAudioConference')) { if (stateObject.isInAudioConference !== this._isInAudioConference) { PubSub.publish('onConferenceStateChange', { isInAudioConference: stateObject.isInAudioConference }); this._isInAudioConference = stateObject.isInAudioConference; } } } // TODO: any public processConferenceNotification(data: any) { if (!data) { this.logger.logError('WebViewWindowController.processConferenceNotification(): No data.'); return; } if (!data.mode) { this.logger.logError('WebViewWindowController.processConferenceNotification(): No data mode.'); return; } this.logger.logMessage( 'ConferenceState.processConferenceNotification: Conference notification: ' + JSON.stringify(data) ); if (data.mode === 'Start') { if (data.type === 'Video') { this.setConferenceState({ isInVideoConference: true }); this.setConferenceState({ isVideoConferenceFullScreen: data.view === 'Full Screen' }); } else if (data.type === 'Audio') { this.setConferenceState({ isInAudioConference: true }); } } else if (data.mode === 'End') { if (data.type === 'Video') { this.setConferenceState({ isInVideoConference: false }); this.setConferenceState({ isVideoConferenceFullScreen: false }); } else if (data.type === 'Audio') { this.setConferenceState({ isInAudioConference: false }); } } this.logger.logMessage( 'ConferenceState.processConferenceNotification: Current conference state: ' + JSON.stringify(this) ); } }