浏览代码

Fix stream end/start race condition

We need to queue attempts to call modifySources to prevent errors in
setLocalDescription, et al. We need to let the asynchronous function
flow in modifySources finish before we kick off another set.
master
Mike Keesey 10 年前
父节点
当前提交
0fdf5e0102
共有 3 个文件被更改,包括 1283 次插入106 次删除
  1. 1266
    85
      libs/app.bundle.js
  2. 15
    20
      modules/xmpp/JingleSession.js
  3. 2
    1
      package.json

+ 1266
- 85
libs/app.bundle.js
文件差异内容过多而无法显示
查看文件


+ 15
- 20
modules/xmpp/JingleSession.js 查看文件

@@ -4,6 +4,7 @@ var SDPDiffer = require("./SDPDiffer");
4 4
 var SDPUtil = require("./SDPUtil");
5 5
 var SDP = require("./SDP");
6 6
 var RTCBrowserType = require("../../service/RTC/RTCBrowserType");
7
+var async = require("async");
7 8
 
8 9
 // Jingle stuff
9 10
 function JingleSession(me, sid, connection, service) {
@@ -52,6 +53,7 @@ function JingleSession(me, sid, connection, service) {
52 53
      * by the application logic.
53 54
      */
54 55
     this.videoMuteByUser = false;
56
+    this.modifySourcesQueue = async.queue(this._modifySources.bind(this), 1);
55 57
 }
56 58
 
57 59
 //TODO: this array must be removed when firefox implement multistream support
@@ -774,7 +776,7 @@ JingleSession.prototype.addSource = function (elem, fromJid) {
774 776
         });
775 777
         sdp.raw = sdp.session + sdp.media.join('');
776 778
     });
777
-    this.modifySources();
779
+    this.modifySourcesQueue.push();
778 780
 };
779 781
 
780 782
 JingleSession.prototype.removeSource = function (elem, fromJid) {
@@ -835,11 +837,12 @@ JingleSession.prototype.removeSource = function (elem, fromJid) {
835 837
         });
836 838
         sdp.raw = sdp.session + sdp.media.join('');
837 839
     });
838
-    this.modifySources();
840
+    this.modifySourcesQueue.push();
839 841
 };
840 842
 
841
-JingleSession.prototype.modifySources = function (successCallback) {
843
+JingleSession.prototype._modifySources = function (successCallback, queueCallback) {
842 844
     var self = this;
845
+
843 846
     if (this.peerconnection.signalingState == 'closed') return;
844 847
     if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null || this.switchstreams)){
845 848
         // There is nothing to do since scheduled job might have been executed by another succeeding call
@@ -847,21 +850,7 @@ JingleSession.prototype.modifySources = function (successCallback) {
847 850
         if(successCallback){
848 851
             successCallback();
849 852
         }
850
-        return;
851
-    }
852
-
853
-    // FIXME: this is a big hack
854
-    // https://code.google.com/p/webrtc/issues/detail?id=2688
855
-    // ^ has been fixed.
856
-    if (!(this.peerconnection.signalingState == 'stable' && this.peerconnection.iceConnectionState == 'connected')) {
857
-        console.warn('modifySources not yet', this.peerconnection.signalingState, this.peerconnection.iceConnectionState);
858
-        this.wait = true;
859
-        window.setTimeout(function() { self.modifySources(successCallback); }, 250);
860
-        return;
861
-    }
862
-    if (this.wait) {
863
-        window.setTimeout(function() { self.modifySources(successCallback); }, 2500);
864
-        this.wait = false;
853
+        queueCallback();
865 854
         return;
866 855
     }
867 856
 
@@ -901,6 +890,7 @@ JingleSession.prototype.modifySources = function (successCallback) {
901 890
 
902 891
             if(self.signalingState == 'closed') {
903 892
                 console.error("createAnswer attempt on closed state");
893
+                queueCallback("createAnswer attempt on closed state");
904 894
                 return;
905 895
             }
906 896
 
@@ -937,23 +927,28 @@ JingleSession.prototype.modifySources = function (successCallback) {
937 927
                             if(successCallback){
938 928
                                 successCallback();
939 929
                             }
930
+                            queueCallback();
940 931
                         },
941 932
                         function(error) {
942 933
                             console.error('modified setLocalDescription failed', error);
934
+                            queueCallback(error);
943 935
                         }
944 936
                     );
945 937
                 },
946 938
                 function(error) {
947 939
                     console.error('modified answer failed', error);
940
+                    queueCallback(error);
948 941
                 }
949 942
             );
950 943
         },
951 944
         function(error) {
952 945
             console.error('modify failed', error);
946
+            queueCallback(error);
953 947
         }
954 948
     );
955 949
 };
956 950
 
951
+
957 952
 /**
958 953
  * Switches video streams.
959 954
  * @param new_stream new stream that will be used as video of this session.
@@ -984,7 +979,7 @@ JingleSession.prototype.switchStreams = function (new_stream, oldStream, success
984 979
     }
985 980
 
986 981
     self.switchstreams = true;
987
-    self.modifySources(function() {
982
+    self.modifySourcesQueue.push(function() {
988 983
         console.log('modify sources done');
989 984
 
990 985
         success_callback();
@@ -1092,7 +1087,7 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
1092 1087
 
1093 1088
     this.hardMuteVideo(mute);
1094 1089
 
1095
-    this.modifySources(callback(mute));
1090
+    this.modifySourcesQueue.push(callback(mute));
1096 1091
 };
1097 1092
 
1098 1093
 JingleSession.prototype.hardMuteVideo = function (muted) {

+ 2
- 1
package.json 查看文件

@@ -19,7 +19,8 @@
19 19
       "pako": "*",
20 20
       "i18next-client": "1.7.7",
21 21
       "sdp-interop": "jitsi/sdp-interop#f65fedfe57a",
22
-      "sdp-transform": "1.3.0"
22
+      "sdp-transform": "1.3.0",
23
+      "async": "0.9.0"
23 24
   },
24 25
   "devDependencies": {
25 26
   },

正在加载...
取消
保存