From e1d849e3a0b7bf7b5c9ce9844bf7cdedb76c9aa5 Mon Sep 17 00:00:00 2001 From: Slava Kisel Date: Tue, 30 Jan 2018 18:43:06 +0500 Subject: [PATCH] Implement external API notification about screen sharing status --- conference.js | 28 ++++++++++++++++++++++------ doc/api.md | 7 +++++++ modules/API/API.js | 14 ++++++++++++++ modules/API/external/external_api.js | 9 ++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/conference.js b/conference.js index 3ec751eb7..18538c57f 100644 --- a/conference.js +++ b/conference.js @@ -1334,19 +1334,35 @@ export default { replaceLocalTrack(this.localVideo, newStream, room)) .then(() => { this.localVideo = newStream; - + this._setSharingScreen(newStream); if (newStream) { - this.isSharingScreen = newStream.videoType === 'desktop'; - APP.UI.addLocalStream(newStream); - } else { - this.isSharingScreen = false; } this.setVideoMuteStatus(this.isLocalVideoMuted()); - APP.UI.updateDesktopSharingButtons(); }); }, + /** + * Sets `this.isSharingScreen` depending on provided video stream. + * In case new screen sharing status is not equal previous one + * it updates desktop sharing buttons in UI + * and notifies external application. + * + * @param {JitsiLocalTrack} [newStream] new stream to use or null + * @private + * @returns {void} + */ + _setSharingScreen(newStream) { + const wasSharingScreen = this.isSharingScreen; + + this.isSharingScreen = newStream && newStream.videoType === 'desktop'; + + if (wasSharingScreen !== this.isSharingScreen) { + APP.UI.updateDesktopSharingButtons(); + APP.API.notifyScreenSharingStatusChanged(this.isSharingScreen); + } + }, + /** * Start using provided audio stream. * Stops previous audio stream. diff --git a/doc/api.md b/doc/api.md index c5361e13d..929f26747 100644 --- a/doc/api.md +++ b/doc/api.md @@ -164,6 +164,13 @@ changes. The listener will receive an object with the following structure: } ``` +* **screenSharingStatusChanged** - receives event notifications about turning on/off the local user screen sharing. The listener will receive object with the following structure: +```javascript +{ +"on": on //whether screen sharing is on +} +``` + * **incomingMessage** - Event notifications about incoming messages. The listener will receive an object with the following structure: ```javascript diff --git a/modules/API/API.js b/modules/API/API.js index a1dcae336..7bed8149a 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -471,6 +471,20 @@ class API { this._sendEvent({ name: 'feedback-submitted' }); } + /** + * Notify external application (if API is enabled) that the screen sharing + * has been turned on/off. + * + * @param {boolean} on - True if screen sharing is enabled. + * @returns {void} + */ + notifyScreenSharingStatusChanged(on: boolean) { + this._sendEvent({ + name: 'screen-sharing-status-changed', + on + }); + } + /** * Disposes the allocated resources. * diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js index 33568d57d..22286a5f4 100644 --- a/modules/API/external/external_api.js +++ b/modules/API/external/external_api.js @@ -48,7 +48,8 @@ const events = { 'video-conference-joined': 'videoConferenceJoined', 'video-conference-left': 'videoConferenceLeft', 'video-availability-changed': 'videoAvailabilityChanged', - 'video-mute-status-changed': 'videoMuteStatusChanged' + 'video-mute-status-changed': 'videoMuteStatusChanged', + 'screen-sharing-status-changed': 'screenSharingStatusChanged' }; /** @@ -485,6 +486,12 @@ export default class JitsiMeetExternalAPI extends EventEmitter { * {{ * roomName: room //the room name of the conference * }} + * screenSharingStatusChanged - receives event notifications about + * turning on/off the local user screen sharing. + * The listener will receive object with the following structure: + * {{ + * on: on //whether screen sharing is on + * }} * readyToClose - all hangup operations are completed and Jitsi Meet is * ready to be disposed. * @returns {void}