diff --git a/modules/API/API.js b/modules/API/API.js index a6dd4c229..1ea7a7754 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -432,6 +432,15 @@ function initCommands() { case 'is-sharing-screen': callback(Boolean(APP.conference.isSharingScreen)); break; + case 'get-content-sharing-participants': { + const tracks = getState()['features/base/tracks']; + const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId); + + callback({ + sharingParticipantIds + }); + break; + } default: return false; } @@ -675,6 +684,19 @@ class API { }); } + /** + * Notify external application (if API is enabled) that the list of sharing participants changed. + * + * @param {Object} data - The event data. + * @returns {void} + */ + notifySharingParticipantsChanged(data: Object) { + this._sendEvent({ + name: 'content-sharing-participants-changed', + data + }); + } + /** * Notify external application (if API is enabled) that the device list has * changed. diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js index d0fccb27a..991fd5805 100644 --- a/modules/API/external/external_api.js +++ b/modules/API/external/external_api.js @@ -64,6 +64,7 @@ const events = { 'audio-availability-changed': 'audioAvailabilityChanged', 'audio-mute-status-changed': 'audioMuteStatusChanged', 'camera-error': 'cameraError', + 'content-sharing-participants-changed': 'contentSharingParticipantsChanged', 'device-list-changed': 'deviceListChanged', 'display-name-change': 'displayNameChange', 'email-change': 'emailChange', @@ -725,6 +726,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter { return getAvailableDevices(this._transport); } + /** + * Gets a list of the currently sharing participant id's. + * + * @returns {Promise} - Resolves with the list of participant id's currently sharing. + */ + getContentSharingParticipants() { + return this._transport.sendRequest({ + name: 'get-content-sharing-participants' + }); + } + /** * Returns Promise that resolves with current selected devices. * diff --git a/react/features/base/tracks/middleware.js b/react/features/base/tracks/middleware.js index 5e62d090b..ebf352ee3 100644 --- a/react/features/base/tracks/middleware.js +++ b/react/features/base/tracks/middleware.js @@ -35,6 +35,8 @@ import { setTrackMuted } from './functions'; +import './subscriber'; + declare var APP: Object; /** diff --git a/react/features/base/tracks/subscriber.js b/react/features/base/tracks/subscriber.js new file mode 100644 index 000000000..0fb7b7ccb --- /dev/null +++ b/react/features/base/tracks/subscriber.js @@ -0,0 +1,24 @@ +// @flow + +import _ from 'lodash'; + +import { StateListenerRegistry } from '../../base/redux'; + +declare var APP: Object; + +/** + * Notifies when the list of currently sharing participants changes. + */ +StateListenerRegistry.register( + /* selector */ state => + state['features/base/tracks'].filter(tr => tr.videoType === 'desktop').map(t => t.participantId), + /* listener */ (participantIDs, store, previousParticipantIDs) => { + if (typeof APP !== 'object') { + return; + } + + if (!_.isEqual(_.sortBy(participantIDs), _.sortBy(previousParticipantIDs))) { + APP.API.notifySharingParticipantsChanged(participantIDs); + } + } +);