Browse Source

Fixes onended handler issues

master
hristoterezov 9 years ago
parent
commit
5c903dfcc3
2 changed files with 32 additions and 7 deletions
  1. 2
    3
      modules/RTC/JitsiLocalTrack.js
  2. 30
    4
      modules/RTC/JitsiTrack.js

+ 2
- 3
modules/RTC/JitsiLocalTrack.js View File

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

+ 30
- 4
modules/RTC/JitsiTrack.js View File

70
     this.type = trackMediaType;
70
     this.type = trackMediaType;
71
     this.track = track;
71
     this.track = track;
72
     this.videoType = videoType;
72
     this.videoType = videoType;
73
+    this.handlers = {};
73
 
74
 
74
     /**
75
     /**
75
      * Indicates whether this JitsiTrack has been disposed. If true, this
76
      * Indicates whether this JitsiTrack has been disposed. If true, this
79
      * @type {boolean}
80
      * @type {boolean}
80
      */
81
      */
81
     this.disposed = false;
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 type {string} the type of the handler that is going to be set
90
+ * @param handler {Function} 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 stream {MediaStream} 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…
Cancel
Save