Selaa lähdekoodia

Better JitsiTrack#dispose() method to prevent memory leaks

master
tsareg 9 vuotta sitten
vanhempi
commit
06cf23ff61

+ 8
- 4
modules/RTC/JitsiLocalTrack.js Näytä tiedosto

37
     this.resolution = resolution;
37
     this.resolution = resolution;
38
     this.deviceId = deviceId;
38
     this.deviceId = deviceId;
39
     this.startMuted = false;
39
     this.startMuted = false;
40
-    this.disposed = false;
41
     this.initialMSID = this.getMSID();
40
     this.initialMSID = this.getMSID();
42
     this.inMuteOrUnmuteProgress = false;
41
     this.inMuteOrUnmuteProgress = false;
43
 
42
 
251
                     }
250
                     }
252
 
251
 
253
                     if(!streamInfo) {
252
                     if(!streamInfo) {
253
+                        // FIXME: introduce new JitsiTrackError for that
254
                         reject(new Error('track.no_stream_found'));
254
                         reject(new Error('track.no_stream_found'));
255
                         return;
255
                         return;
256
                     }
256
                     }
287
 /**
287
 /**
288
  * Stops sending the media track. And removes it from the HTML.
288
  * Stops sending the media track. And removes it from the HTML.
289
  * NOTE: Works for local tracks only.
289
  * NOTE: Works for local tracks only.
290
+ *
291
+ * @extends JitsiTrack#dispose
290
  * @returns {Promise}
292
  * @returns {Promise}
291
  */
293
  */
292
 JitsiLocalTrack.prototype.dispose = function () {
294
 JitsiLocalTrack.prototype.dispose = function () {
295
+    var self = this;
293
     var promise = Promise.resolve();
296
     var promise = Promise.resolve();
294
 
297
 
295
     if (this.conference){
298
     if (this.conference){
301
         this.detach();
304
         this.detach();
302
     }
305
     }
303
 
306
 
304
-    this.disposed = true;
305
-
306
     RTCUtils.removeListener(RTCEvents.DEVICE_LIST_CHANGED,
307
     RTCUtils.removeListener(RTCEvents.DEVICE_LIST_CHANGED,
307
         this._onDeviceListChanged);
308
         this._onDeviceListChanged);
308
 
309
 
311
             this._onAudioOutputDeviceChanged);
312
             this._onAudioOutputDeviceChanged);
312
     }
313
     }
313
 
314
 
314
-    return promise;
315
+    return promise
316
+        .then(function() {
317
+            return JitsiTrack.prototype.dispose.call(self);
318
+        });
315
 };
319
 };
316
 
320
 
317
 /**
321
 /**

+ 0
- 2
modules/RTC/JitsiRemoteTrack.js Näytä tiedosto

84
     this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
84
     this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
85
 };
85
 };
86
 
86
 
87
-delete JitsiRemoteTrack.prototype.dispose;
88
-
89
 module.exports = JitsiRemoteTrack;
87
 module.exports = JitsiRemoteTrack;

+ 10
- 2
modules/RTC/JitsiTrack.js Näytä tiedosto

71
     this.track = track;
71
     this.track = track;
72
     this.videoType = videoType;
72
     this.videoType = videoType;
73
 
73
 
74
+    this.disposed = false;
75
+
74
     if(stream) {
76
     if(stream) {
75
         if (RTCBrowserType.isFirefox()) {
77
         if (RTCBrowserType.isFirefox()) {
76
             implementOnEndedHandling(this);
78
             implementOnEndedHandling(this);
208
 };
210
 };
209
 
211
 
210
 /**
212
 /**
211
- * Dispose sending the media track. And removes it from the HTML.
212
- * NOTE: Works for local tracks only.
213
+ * Removes attached event listeners.
214
+ *
215
+ * @returns {Promise}
213
  */
216
  */
214
 JitsiTrack.prototype.dispose = function () {
217
 JitsiTrack.prototype.dispose = function () {
218
+    this.eventEmitter.removeAllListeners();
219
+
220
+    this.disposed = true;
221
+
222
+    return Promise.resolve();
215
 };
223
 };
216
 
224
 
217
 /**
225
 /**

+ 7
- 0
modules/RTC/RTCUtils.js Näytä tiedosto

1101
             mediaStream.stop();
1101
             mediaStream.stop();
1102
         }
1102
         }
1103
 
1103
 
1104
+        // MediaStream in react-native-webrtc implementation has special
1105
+        // "release" method to do the clean up of memory. We use it to prevent
1106
+        // memory leaks.
1107
+        if (mediaStream.release) {
1108
+            mediaStream.release();
1109
+        }
1110
+
1104
         // if we have done createObjectURL, lets clean it
1111
         // if we have done createObjectURL, lets clean it
1105
         var url = mediaStream.jitsiObjectURL;
1112
         var url = mediaStream.jitsiObjectURL;
1106
         if (url) {
1113
         if (url) {

Loading…
Peruuta
Tallenna