浏览代码

Sdp overhaul (#1234)

* M1: device change now uses new flow.  fundamentally "works" but may be corner cases/side effects to other flows. haven't touched ffox yet

* M2: change toggle screenshare flows to use the new video replacement chain

* remove the old 'useVideoStream' and replace it with the new one

* use the new (and renamed back from the shim) 'dispose' method

* tweaks to work with the sdp overhaul changes in lib-jitsi-meet

* change the order in which we call dispose (to handle dispose being reverted back to how it is currently on master)

* move useAudioStream over to new flow

* restore useVideoStream doc

* handle rename JitsiConference::replaceStream -> JitsiConference::replaceTrack

* fix useAudioStream and useVideoStream to return a promise again
j8
bbaldino 8 年前
父节点
当前提交
5baa167a08
共有 1 个文件被更改,包括 56 次插入61 次删除
  1. 56
    61
      conference.js

+ 56
- 61
conference.js 查看文件

@@ -901,43 +901,40 @@ export default {
901 901
         return options;
902 902
     },
903 903
 
904
-    /**
905
-     * Start using provided video stream.
906
-     * Stops previous video stream.
907
-     * @param {JitsiLocalTrack} [stream] new stream to use or null
908
-     * @returns {Promise}
909
-     */
910
-    useVideoStream (stream) {
911
-        let promise = Promise.resolve();
912
-        if (localVideo) {
913
-            // this calls room.removeTrack internally
914
-            // so we don't need to remove it manually
915
-            promise = localVideo.dispose();
916
-        }
917
-        localVideo = stream;
918 904
 
919
-        return promise.then(function () {
920
-            if (stream) {
921
-                return room.addTrack(stream);
922
-            }
923
-        }).then(() => {
924
-            if (stream) {
925
-                this.videoMuted = stream.isMuted();
926
-                this.isSharingScreen = stream.videoType === 'desktop';
927
-
928
-                APP.UI.addLocalStream(stream);
929
-
930
-                stream.videoType === 'camera'
931
-                    && APP.UI.setCameraButtonEnabled(true);
932
-            } else {
933
-                this.videoMuted = false;
934
-                this.isSharingScreen = false;
935
-            }
905
+  /**
906
+   * Start using provided video stream.
907
+   * Stops previous video stream.
908
+   * @param {JitsiLocalTrack} [stream] new stream to use or null
909
+   * @returns {Promise}
910
+   */
911
+    useVideoStream (newStream) {
912
+        return room.replaceTrack(localVideo, newStream)
913
+            .then(() => {
914
+                // We call dispose after doing the replace because
915
+                //  dispose will try and do a new o/a after the
916
+                //  track removes itself.  Doing it after means
917
+                //  the JitsiLocalTrack::conference member is already
918
+                //  cleared, so it won't try and do the o/a
919
+                if (localVideo) {
920
+                    localVideo.dispose();
921
+                }
922
+                localVideo = newStream;
923
+                if (newStream) {
924
+                    this.videoMuted = newStream.isMuted();
925
+                    this.isSharingScreen = newStream.videoType === 'desktop';
936 926
 
937
-            APP.UI.setVideoMuted(this.getMyUserId(), this.videoMuted);
927
+                    APP.UI.addLocalStream(newStream);
938 928
 
939
-            APP.UI.updateDesktopSharingButtons();
940
-        });
929
+                    newStream.videoType === 'camera'
930
+                        && APP.UI.setCameraButtonEnabled(true);
931
+                } else {
932
+                    this.videoMuted = false;
933
+                    this.isSharingScreen = false;
934
+                }
935
+                APP.UI.setVideoMuted(this.getMyUserId(), this.videoMuted);
936
+                APP.UI.updateDesktopSharingButtons();
937
+            });
941 938
     },
942 939
 
943 940
     /**
@@ -946,31 +943,27 @@ export default {
946 943
      * @param {JitsiLocalTrack} [stream] new stream to use or null
947 944
      * @returns {Promise}
948 945
      */
949
-    useAudioStream (stream) {
950
-        let promise = Promise.resolve();
951
-        if (localAudio) {
952
-            // this calls room.removeTrack internally
953
-            // so we don't need to remove it manually
954
-            promise = localAudio.dispose();
955
-        }
956
-        localAudio = stream;
957
-
958
-        return promise.then(function () {
959
-            if (stream) {
960
-                return room.addTrack(stream);
961
-            }
962
-        }).then(() => {
963
-            if (stream) {
964
-                this.audioMuted = stream.isMuted();
965
-
966
-                APP.UI.addLocalStream(stream);
967
-            } else {
968
-                this.audioMuted = false;
969
-            }
970
-
971
-            APP.UI.setMicrophoneButtonEnabled(true);
972
-            APP.UI.setAudioMuted(this.getMyUserId(), this.audioMuted);
973
-        });
946
+    useAudioStream (newStream) {
947
+        return room.replaceTrack(localAudio, newStream)
948
+            .then(() => {
949
+                // We call dispose after doing the replace because
950
+                //  dispose will try and do a new o/a after the
951
+                //  track removes itself.  Doing it after means
952
+                //  the JitsiLocalTrack::conference member is already
953
+                //  cleared, so it won't try and do the o/a
954
+                if (localAudio) {
955
+                    localAudio.dispose();
956
+                }
957
+                localAudio = newStream;
958
+                if (newStream) {
959
+                    this.audioMuted = newStream.isMuted();
960
+                    APP.UI.addLocalStream(newStream);
961
+                } else {
962
+                    this.audioMuted = false;
963
+                }
964
+                APP.UI.setMicrophoneButtonEnabled(true);
965
+                APP.UI.setAudioMuted(this.getMyUserId(), this.audioMuted);
966
+            });
974 967
     },
975 968
 
976 969
     videoSwitchInProgress: false,
@@ -1344,11 +1337,13 @@ export default {
1344 1337
                     this.deviceChangeListener);
1345 1338
 
1346 1339
             // stop local video
1347
-            if (localVideo)
1340
+            if (localVideo) {
1348 1341
                 localVideo.dispose();
1342
+            }
1349 1343
             // stop local audio
1350
-            if (localAudio)
1344
+            if (localAudio) {
1351 1345
                 localAudio.dispose();
1346
+            }
1352 1347
 
1353 1348
             // show overlay
1354 1349
             APP.UI.showSuspendedOverlay();

正在加载...
取消
保存