瀏覽代碼

feat(external_api) add command and event listener for CS

j8
hmuresan 4 年之前
父節點
當前提交
4dda508708

+ 22
- 0
modules/API/API.js 查看文件

@@ -413,6 +413,15 @@ function initCommands() {
413 413
         case 'is-sharing-screen':
414 414
             callback(Boolean(APP.conference.isSharingScreen));
415 415
             break;
416
+        case 'get-content-sharing-participants': {
417
+            const tracks = getState()['features/base/tracks'];
418
+            const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId);
419
+
420
+            callback({
421
+                sharingParticipantIds
422
+            });
423
+            break;
424
+        }
416 425
         default:
417 426
             return false;
418 427
         }
@@ -656,6 +665,19 @@ class API {
656 665
         });
657 666
     }
658 667
 
668
+    /**
669
+     * Notify external application (if API is enabled) that the list of sharing participants changed.
670
+     *
671
+     * @param {Object} data - The event data.
672
+     * @returns {void}
673
+     */
674
+    notifySharingParticipantsChanged(data: Object) {
675
+        this._sendEvent({
676
+            name: 'content-sharing-participants-changed',
677
+            data
678
+        });
679
+    }
680
+
659 681
     /**
660 682
      * Notify external application (if API is enabled) that the device list has
661 683
      * changed.

+ 12
- 0
modules/API/external/external_api.js 查看文件

@@ -62,6 +62,7 @@ const events = {
62 62
     'audio-availability-changed': 'audioAvailabilityChanged',
63 63
     'audio-mute-status-changed': 'audioMuteStatusChanged',
64 64
     'camera-error': 'cameraError',
65
+    'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
65 66
     'device-list-changed': 'deviceListChanged',
66 67
     'display-name-change': 'displayNameChange',
67 68
     'email-change': 'emailChange',
@@ -723,6 +724,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
723 724
         return getAvailableDevices(this._transport);
724 725
     }
725 726
 
727
+    /**
728
+     * Gets a list of the currently sharing participant id's.
729
+     *
730
+     * @returns {Promise} - Resolves with the list of participant id's currently sharing.
731
+     */
732
+    getContentSharingParticipants() {
733
+        return this._transport.sendRequest({
734
+            name: 'get-content-sharing-participants'
735
+        });
736
+    }
737
+
726 738
     /**
727 739
      * Returns Promise that resolves with current selected devices.
728 740
      *

+ 2
- 0
react/features/base/tracks/middleware.js 查看文件

@@ -35,6 +35,8 @@ import {
35 35
     setTrackMuted
36 36
 } from './functions';
37 37
 
38
+import './subscriber';
39
+
38 40
 declare var APP: Object;
39 41
 
40 42
 /**

+ 24
- 0
react/features/base/tracks/subscriber.js 查看文件

@@ -0,0 +1,24 @@
1
+// @flow
2
+
3
+import _ from 'lodash';
4
+
5
+import { StateListenerRegistry } from '../../base/redux';
6
+
7
+declare var APP: Object;
8
+
9
+/**
10
+ * Notifies when the list of currently sharing participants changes.
11
+ */
12
+StateListenerRegistry.register(
13
+    /* selector */ state =>
14
+        state['features/base/tracks'].filter(tr => tr.videoType === 'desktop').map(t => t.participantId),
15
+    /* listener */ (participantIDs, store, previousParticipantIDs) => {
16
+        if (typeof APP !== 'object') {
17
+            return;
18
+        }
19
+
20
+        if (!_.isEqual(_.sortBy(participantIDs), _.sortBy(previousParticipantIDs))) {
21
+            APP.API.notifySharingParticipantsChanged(participantIDs);
22
+        }
23
+    }
24
+);

Loading…
取消
儲存