浏览代码

Merge pull request #552 from damencho/shared-video-fixes

Shared video fixes
j8
yanas 9 年前
父节点
当前提交
1e7cd06555
共有 5 个文件被更改,包括 56 次插入27 次删除
  1. 25
    7
      conference.js
  2. 6
    1
      modules/FollowMe.js
  3. 12
    9
      modules/UI/UI.js
  4. 11
    8
      modules/UI/shared_video/SharedVideo.js
  5. 2
    2
      modules/UI/videolayout/VideoLayout.js

+ 25
- 7
conference.js 查看文件

402
     listMembersIds () {
402
     listMembersIds () {
403
         return room.getParticipants().map(p => p.getId());
403
         return room.getParticipants().map(p => p.getId());
404
     },
404
     },
405
+    /**
406
+     * Checks whether the participant identified by id is a moderator.
407
+     * @id id to search for participant
408
+     * @return {boolean} whether the participant is moderator
409
+     */
410
+    isParticipantModerator (id) {
411
+        let user = room.getParticipantById(id);
412
+        return user && user.isModerator();
413
+    },
405
     /**
414
     /**
406
      * Check if SIP is supported.
415
      * Check if SIP is supported.
407
      * @returns {boolean}
416
      * @returns {boolean}
737
             console.log('USER %s LEFT', id, user);
746
             console.log('USER %s LEFT', id, user);
738
             APP.API.notifyUserLeft(id);
747
             APP.API.notifyUserLeft(id);
739
             APP.UI.removeUser(id, user.getDisplayName());
748
             APP.UI.removeUser(id, user.getDisplayName());
740
-            APP.UI.stopSharedVideo({from: id});
749
+            APP.UI.stopSharedVideo(id);
741
         });
750
         });
742
 
751
 
743
 
752
 
1083
                 room.sendCommandOnce(Commands.SHARED_VIDEO, {
1092
                 room.sendCommandOnce(Commands.SHARED_VIDEO, {
1084
                     value: url,
1093
                     value: url,
1085
                     attributes: {
1094
                     attributes: {
1086
-                        from: APP.conference.localId,
1087
                         state: state,
1095
                         state: state,
1088
                         time: time,
1096
                         time: time,
1089
                         volume: volume
1097
                         volume: volume
1096
                 room.sendCommand(Commands.SHARED_VIDEO, {
1104
                 room.sendCommand(Commands.SHARED_VIDEO, {
1097
                     value: url,
1105
                     value: url,
1098
                     attributes: {
1106
                     attributes: {
1099
-                        from: APP.conference.localId,
1100
                         state: state,
1107
                         state: state,
1101
                         time: time,
1108
                         time: time,
1102
                         volume: volume
1109
                         volume: volume
1105
             }
1112
             }
1106
         });
1113
         });
1107
         room.addCommandListener(
1114
         room.addCommandListener(
1108
-            Commands.SHARED_VIDEO, ({value, attributes}) => {
1115
+            Commands.SHARED_VIDEO, ({value, attributes}, id) => {
1116
+
1117
+                // if we are not the moderator or
1118
+                // the command is coming from a user which is not the moderator
1119
+                if (!(this.isLocalId(id) && room.isModerator())
1120
+                    && !this.isParticipantModerator(id))
1121
+                {
1122
+                    console.warn('Received shared video command ' +
1123
+                        'not from moderator');
1124
+                    return;
1125
+                }
1126
+
1109
                 if (attributes.state === 'stop') {
1127
                 if (attributes.state === 'stop') {
1110
-                    APP.UI.stopSharedVideo(attributes);
1128
+                    APP.UI.stopSharedVideo(id, attributes);
1111
                 } else if (attributes.state === 'start') {
1129
                 } else if (attributes.state === 'start') {
1112
-                    APP.UI.showSharedVideo(value, attributes);
1130
+                    APP.UI.showSharedVideo(id, value, attributes);
1113
                 } else if (attributes.state === 'playing'
1131
                 } else if (attributes.state === 'playing'
1114
                     || attributes.state === 'pause') {
1132
                     || attributes.state === 'pause') {
1115
-                    APP.UI.updateSharedVideo(value, attributes);
1133
+                    APP.UI.updateSharedVideo(id, value, attributes);
1116
                 }
1134
                 }
1117
             });
1135
             });
1118
     }
1136
     }

+ 6
- 1
modules/FollowMe.js 查看文件

270
         if (this._conference.isLocalId(id))
270
         if (this._conference.isLocalId(id))
271
             return;
271
             return;
272
 
272
 
273
-        // TODO Don't obey commands issued by non-moderators.
273
+        if (!this._conference.isParticipantModerator(id))
274
+        {
275
+            console.warn('Received follow-me command ' +
276
+                'not from moderator');
277
+            return;
278
+        }
274
 
279
 
275
         // Applies the received/remote command to the user experience/interface
280
         // Applies the received/remote command to the user experience/interface
276
         // of the local participant.
281
         // of the local participant.

+ 12
- 9
modules/UI/UI.js 查看文件

1107
 };
1107
 };
1108
 
1108
 
1109
 /**
1109
 /**
1110
-* Show shared video.
1111
-* @param {string} url video url
1112
-* @param {string} attributes
1110
+ * Show shared video.
1111
+ * @param {string} id the id of the sender of the command
1112
+ * @param {string} url video url
1113
+ * @param {string} attributes
1113
 */
1114
 */
1114
-UI.showSharedVideo = function (url, attributes) {
1115
+UI.showSharedVideo = function (id, url, attributes) {
1115
     if (sharedVideoManager)
1116
     if (sharedVideoManager)
1116
-        sharedVideoManager.showSharedVideo(url, attributes);
1117
+        sharedVideoManager.showSharedVideo(id, url, attributes);
1117
 };
1118
 };
1118
 
1119
 
1119
 /**
1120
 /**
1120
  * Update shared video.
1121
  * Update shared video.
1122
+ * @param {string} id the id of the sender of the command
1121
  * @param {string} url video url
1123
  * @param {string} url video url
1122
  * @param {string} attributes
1124
  * @param {string} attributes
1123
  */
1125
  */
1124
-UI.updateSharedVideo = function (url, attributes) {
1126
+UI.updateSharedVideo = function (id, url, attributes) {
1125
     if (sharedVideoManager)
1127
     if (sharedVideoManager)
1126
-        sharedVideoManager.updateSharedVideo(url, attributes);
1128
+        sharedVideoManager.updateSharedVideo(id, url, attributes);
1127
 };
1129
 };
1128
 
1130
 
1129
 /**
1131
 /**
1130
  * Stop showing shared video.
1132
  * Stop showing shared video.
1133
+ * @param {string} id the id of the sender of the command
1131
  * @param {string} attributes
1134
  * @param {string} attributes
1132
  */
1135
  */
1133
-UI.stopSharedVideo = function (attributes) {
1136
+UI.stopSharedVideo = function (id, attributes) {
1134
     if (sharedVideoManager)
1137
     if (sharedVideoManager)
1135
-        sharedVideoManager.stopSharedVideo(attributes);
1138
+        sharedVideoManager.stopSharedVideo(id, attributes);
1136
 };
1139
 };
1137
 
1140
 
1138
 module.exports = UI;
1141
 module.exports = UI;

+ 11
- 8
modules/UI/shared_video/SharedVideo.js 查看文件

50
     /**
50
     /**
51
      * Shows the player component and starts the checking function
51
      * Shows the player component and starts the checking function
52
      * that will be sending updates, if we are the one shared the video
52
      * that will be sending updates, if we are the one shared the video
53
+     * @param id the id of the sender of the command
53
      * @param url the video url
54
      * @param url the video url
54
      * @param attributes
55
      * @param attributes
55
      */
56
      */
56
-    showSharedVideo (url, attributes) {
57
+    showSharedVideo (id, url, attributes) {
57
         if (this.isSharedVideoShown)
58
         if (this.isSharedVideoShown)
58
             return;
59
             return;
59
 
60
 
61
         this.url = url;
62
         this.url = url;
62
 
63
 
63
         // the owner of the video
64
         // the owner of the video
64
-        this.from = attributes.from;
65
+        this.from = id;
65
 
66
 
66
         // This code loads the IFrame Player API code asynchronously.
67
         // This code loads the IFrame Player API code asynchronously.
67
         var tag = document.createElement('script');
68
         var tag = document.createElement('script');
184
     /**
185
     /**
185
      * Updates video, if its not playing and needs starting or
186
      * Updates video, if its not playing and needs starting or
186
      * if its playing and needs to be paysed
187
      * if its playing and needs to be paysed
188
+     * @param id the id of the sender of the command
187
      * @param url the video url
189
      * @param url the video url
188
      * @param attributes
190
      * @param attributes
189
      */
191
      */
190
-    updateSharedVideo (url, attributes) {
192
+    updateSharedVideo (id, url, attributes) {
191
         // if we are sending the event ignore
193
         // if we are sending the event ignore
192
         if(APP.conference.isLocalId(this.from)) {
194
         if(APP.conference.isLocalId(this.from)) {
193
             return;
195
             return;
196
         if (attributes.state == 'playing') {
198
         if (attributes.state == 'playing') {
197
 
199
 
198
             if(!this.isSharedVideoShown) {
200
             if(!this.isSharedVideoShown) {
199
-                this.showSharedVideo(url, attributes);
201
+                this.showSharedVideo(id, url, attributes);
200
                 return;
202
                 return;
201
             }
203
             }
202
 
204
 
239
             else {
241
             else {
240
                 // if not shown show it, passing attributes so it can
242
                 // if not shown show it, passing attributes so it can
241
                 // be shown paused
243
                 // be shown paused
242
-                this.showSharedVideo(url, attributes);
244
+                this.showSharedVideo(id, url, attributes);
243
             }
245
             }
244
         }
246
         }
245
     }
247
     }
246
 
248
 
247
     /**
249
     /**
248
      * Stop shared video if it is currently showed. If the user started the
250
      * Stop shared video if it is currently showed. If the user started the
249
-     * shared video is the one in the attributes.from (called when user
251
+     * shared video is the one in the id (called when user
250
      * left and we want to remove video if the user sharing it left).
252
      * left and we want to remove video if the user sharing it left).
253
+     * @param id the id of the sender of the command
251
      * @param attributes
254
      * @param attributes
252
      */
255
      */
253
-    stopSharedVideo (attributes) {
256
+    stopSharedVideo (id, attributes) {
254
         if (!this.isSharedVideoShown)
257
         if (!this.isSharedVideoShown)
255
             return;
258
             return;
256
 
259
 
257
-        if(this.from !== attributes.from)
260
+        if(this.from !== id)
258
             return;
261
             return;
259
 
262
 
260
         if(this.intervalId) {
263
         if(this.intervalId) {

+ 2
- 2
modules/UI/videolayout/VideoLayout.js 查看文件

922
         let currentId = largeVideo.id;
922
         let currentId = largeVideo.id;
923
 
923
 
924
         if (!isOnLarge || forceUpdate) {
924
         if (!isOnLarge || forceUpdate) {
925
-            if (id !== currentId) {
925
+            let videoType = this.getRemoteVideoType(id);
926
+            if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
926
                 eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
927
                 eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
927
             }
928
             }
928
             if (currentId) {
929
             if (currentId) {
931
 
932
 
932
             let smallVideo = this.getSmallVideo(id);
933
             let smallVideo = this.getSmallVideo(id);
933
 
934
 
934
-            let videoType = this.getRemoteVideoType(id);
935
             largeVideo.updateLargeVideo(
935
             largeVideo.updateLargeVideo(
936
                 id,
936
                 id,
937
                 smallVideo.videoStream,
937
                 smallVideo.videoStream,

正在加载...
取消
保存