Browse Source

Makes sure we use stream.ended in one place.

master
damencho 10 years ago
parent
commit
74227e182a
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      modules/RTC/LocalStream.js

+ 13
- 4
modules/RTC/LocalStream.js View File

9
  * @param stream original WebRTC stream object to which 'onended' handling
9
  * @param stream original WebRTC stream object to which 'onended' handling
10
  *               will be added.
10
  *               will be added.
11
  */
11
  */
12
-function implementOnEndedHandling(stream) {
12
+function implementOnEndedHandling(localStream) {
13
+    var stream = localStream.getOriginalStream();
13
     var originalStop = stream.stop;
14
     var originalStop = stream.stop;
14
     stream.stop = function () {
15
     stream.stop = function () {
15
         originalStop.apply(stream);
16
         originalStop.apply(stream);
16
-        if (!stream.ended) {
17
+        if (localStream.isActive()) {
17
             stream.ended = true;
18
             stream.ended = true;
18
             stream.onended();
19
             stream.onended();
19
         }
20
         }
46
         });
47
         });
47
 
48
 
48
     if (RTCBrowserType.isFirefox()) {
49
     if (RTCBrowserType.isFirefox()) {
49
-        implementOnEndedHandling(this.stream);
50
+        implementOnEndedHandling(this);
50
     }
51
     }
51
 }
52
 }
52
 
53
 
109
     if (this.isAudioStream()) {
110
     if (this.isAudioStream()) {
110
         tracks = this.stream.getAudioTracks();
111
         tracks = this.stream.getAudioTracks();
111
     } else {
112
     } else {
112
-        if (this.stream.ended)
113
+        if (this.isActive())
113
             return true;
114
             return true;
114
         tracks = this.stream.getVideoTracks();
115
         tracks = this.stream.getVideoTracks();
115
     }
116
     }
124
     return this.stream.getTracks()[0].id;
125
     return this.stream.getTracks()[0].id;
125
 };
126
 };
126
 
127
 
128
+/**
129
+ * Checks whether the MediaStream is avtive/not ended.
130
+ * @returns {boolean} whether MediaStream is active.
131
+ */
132
+LocalStream.prototype.isActive = function () {
133
+    return !this.stream.ended;
134
+};
135
+
127
 module.exports = LocalStream;
136
 module.exports = LocalStream;

Loading…
Cancel
Save