瀏覽代碼

Merge pull request #230 from jitsi/fix_ended_handler

Fixes onended handler issues
master
Paweł Domas 9 年之前
父節點
當前提交
7fd3b67734
共有 2 個檔案被更改,包括 32 行新增7 行删除
  1. 2
    3
      modules/RTC/JitsiLocalTrack.js
  2. 30
    4
      modules/RTC/JitsiTrack.js

+ 2
- 3
modules/RTC/JitsiLocalTrack.js 查看文件

@@ -206,7 +206,6 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
206 206
         this.isAudioTrack() ||
207 207
         this.videoType === VideoType.DESKTOP ||
208 208
         RTCBrowserType.isFirefox()) {
209
-
210 209
         if(this.track)
211 210
             this.track.enabled = !mute;
212 211
     } else {
@@ -218,7 +217,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
218 217
                     //FIXME: Maybe here we should set the SRC for the containers
219 218
                     // to something
220 219
                     RTCUtils.stopMediaStream(self.stream);
221
-                    self.stream = null;
220
+                    self._setStream(null);
222 221
                 });
223 222
         } else {
224 223
             // This path is only for camera.
@@ -240,7 +239,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
240 239
                         throw new JitsiTrackError(
241 240
                             JitsiTrackErrors.TRACK_NO_STREAM_FOUND);
242 241
                     }else {
243
-                        self.stream = streamInfo.stream;
242
+                        self._setStream(streamInfo.stream);
244 243
                         self.track = streamInfo.track;
245 244
                         // This is not good when video type changes after
246 245
                         // unmute, but let's not crash here

+ 30
- 4
modules/RTC/JitsiTrack.js 查看文件

@@ -70,6 +70,7 @@ function JitsiTrack(conference, stream, track, streamInactiveHandler, trackMedia
70 70
     this.type = trackMediaType;
71 71
     this.track = track;
72 72
     this.videoType = videoType;
73
+    this.handlers = {};
73 74
 
74 75
     /**
75 76
      * Indicates whether this JitsiTrack has been disposed. If true, this
@@ -79,13 +80,38 @@ function JitsiTrack(conference, stream, track, streamInactiveHandler, trackMedia
79 80
      * @type {boolean}
80 81
      */
81 82
     this.disposed = false;
83
+    this._setHandler("inactive", streamInactiveHandler);
84
+}
82 85
 
83
-    if(stream) {
84
-        if (RTCBrowserType.isFirefox()) {
85
-            implementOnEndedHandling(this);
86
+/**
87
+ * Sets handler to the WebRTC MediaStream or MediaStreamTrack object depending
88
+ * on the passed type.
89
+ * @param {string} type the type of the handler that is going to be set
90
+ * @param {Function} handler the handler.
91
+ */
92
+JitsiTrack.prototype._setHandler = function (type, handler) {
93
+    if(this.stream) {
94
+        if(type === "inactive") {
95
+            if (RTCBrowserType.isFirefox()) {
96
+                implementOnEndedHandling(this);
97
+            }
98
+            addMediaStreamInactiveHandler(this.stream, handler);
86 99
         }
87
-        addMediaStreamInactiveHandler(stream, streamInactiveHandler);
88 100
     }
101
+    this.handlers[type] = handler;
102
+}
103
+
104
+/**
105
+ * Sets the stream property of JitsiTrack object and sets all stored handlers
106
+ * to it.
107
+ * @param {MediaStream} stream the new stream.
108
+ */
109
+JitsiTrack.prototype._setStream = function (stream) {
110
+    this.stream = stream;
111
+    Object.keys(this.handlers).forEach(function (type) {
112
+        typeof(this.handlers[type]) === "function" &&
113
+            this._setHandler(type, this.handlers[type]);
114
+    }, this);
89 115
 }
90 116
 
91 117
 /**

Loading…
取消
儲存