瀏覽代碼

Updates latest changes.

dev1
damencho 10 年之前
父節點
當前提交
562e57fe96
共有 1 個文件被更改,包括 60 次插入19 次删除
  1. 60
    19
      lib-jitsi-meet.js

+ 60
- 19
lib-jitsi-meet.js 查看文件

987
 function JitsiLocalTrack(RTC, stream, eventEmitter, videoType,
987
 function JitsiLocalTrack(RTC, stream, eventEmitter, videoType,
988
   resolution)
988
   resolution)
989
 {
989
 {
990
-    JitsiTrack.call(this, RTC, stream);
990
+    JitsiTrack.call(this, RTC, stream,
991
+        function () {
992
+            if(!self.dontFireRemoveEvent)
993
+                self.eventEmitter.emit(
994
+                    StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
995
+            self.dontFireRemoveEvent = false;
996
+        });
991
     this.eventEmitter = eventEmitter;
997
     this.eventEmitter = eventEmitter;
992
     this.videoType = videoType;
998
     this.videoType = videoType;
993
     this.dontFireRemoveEvent = false;
999
     this.dontFireRemoveEvent = false;
994
     this.resolution = resolution;
1000
     this.resolution = resolution;
995
     var self = this;
1001
     var self = this;
996
-    this.stream.onended = function () {
997
-        if(!self.dontFireRemoveEvent)
998
-            self.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
999
-        self.dontFireRemoveEvent = false;
1000
-    };
1001
 }
1002
 }
1002
 
1003
 
1003
 JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
1004
 JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
1107
     if (isAudio) {
1108
     if (isAudio) {
1108
         tracks = this.stream.getAudioTracks();
1109
         tracks = this.stream.getAudioTracks();
1109
     } else {
1110
     } else {
1110
-        if (this.stream.ended)
1111
+        if (!this.isActive())
1111
             return true;
1112
             return true;
1112
         tracks = this.stream.getVideoTracks();
1113
         tracks = this.stream.getVideoTracks();
1113
     }
1114
     }
1142
  * @constructor
1143
  * @constructor
1143
  */
1144
  */
1144
 function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
1145
 function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
1145
-    JitsiTrack.call(this, RTC, data.stream);
1146
+    JitsiTrack.call(this, RTC, data.stream,
1147
+        function () {
1148
+            eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, self);
1149
+        });
1146
     this.rtc = RTC;
1150
     this.rtc = RTC;
1147
     this.sid = sid;
1151
     this.sid = sid;
1148
     this.stream = data.stream;
1152
     this.stream = data.stream;
1156
     }
1160
     }
1157
     this.eventEmitter = eventEmitter;
1161
     this.eventEmitter = eventEmitter;
1158
     var self = this;
1162
     var self = this;
1159
-    if(this.stream)
1160
-        this.stream.onended = function () {
1161
-            eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, self);
1162
-        }
1163
 }
1163
 }
1164
 
1164
 
1165
 JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
1165
 JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
1203
 /**
1203
 /**
1204
  * This implements 'onended' callback normally fired by WebRTC after the stream
1204
  * This implements 'onended' callback normally fired by WebRTC after the stream
1205
  * is stopped. There is no such behaviour yet in FF, so we have to add it.
1205
  * is stopped. There is no such behaviour yet in FF, so we have to add it.
1206
- * @param stream original WebRTC stream object to which 'onended' handling
1207
- *               will be added.
1206
+ * @param jitsiTrack our track object holding the original WebRTC stream object
1207
+ * to which 'onended' handling will be added.
1208
  */
1208
  */
1209
-function implementOnEndedHandling(stream) {
1209
+function implementOnEndedHandling(jitsiTrack) {
1210
+    var stream = jitsiTrack.getOriginalStream();
1210
     var originalStop = stream.stop;
1211
     var originalStop = stream.stop;
1211
     stream.stop = function () {
1212
     stream.stop = function () {
1212
         originalStop.apply(stream);
1213
         originalStop.apply(stream);
1213
-        if (!stream.ended) {
1214
-            stream.ended = true;
1214
+        if (jitsiTrack.isActive()) {
1215
             stream.onended();
1215
             stream.onended();
1216
         }
1216
         }
1217
     };
1217
     };
1218
 }
1218
 }
1219
 
1219
 
1220
+/**
1221
+ * Adds onended/oninactive handler to a MediaStream.
1222
+ * @param mediaStream a MediaStream to attach onended/oninactive handler
1223
+ * @param handler the handler
1224
+ */
1225
+function addMediaStreamInactiveHandler(mediaStream, handler) {
1226
+    if (mediaStream.addEventListener) {
1227
+        // chrome
1228
+        if(typeof mediaStream.active !== "undefined")
1229
+            mediaStream.oninactive = handler;
1230
+        else
1231
+            mediaStream.onended = handler;
1232
+    } else {
1233
+        // themasys
1234
+        mediaStream.attachEvent('ended', function () {
1235
+            handler(mediaStream);
1236
+        });
1237
+    }
1238
+}
1239
+
1220
 /**
1240
 /**
1221
  * Represents a single media track (either audio or video).
1241
  * Represents a single media track (either audio or video).
1222
  * @constructor
1242
  * @constructor
1243
+ * @param rtc the rtc instance
1244
+ * @param stream the stream
1245
+ * @param streamInactiveHandler the function that will handle
1246
+ *        onended/oninactive events of the stream.
1223
  */
1247
  */
1224
-function JitsiTrack(rtc, stream)
1248
+function JitsiTrack(rtc, stream, streamInactiveHandler)
1225
 {
1249
 {
1226
     /**
1250
     /**
1227
      * Array with the HTML elements that are displaying the streams.
1251
      * Array with the HTML elements that are displaying the streams.
1242
         }.bind(this);
1266
         }.bind(this);
1243
     }
1267
     }
1244
     if (RTCBrowserType.isFirefox() && this.stream) {
1268
     if (RTCBrowserType.isFirefox() && this.stream) {
1245
-        implementOnEndedHandling(this.stream);
1269
+        implementOnEndedHandling(this);
1246
     }
1270
     }
1271
+
1272
+    if(stream)
1273
+        addMediaStreamInactiveHandler(stream, streamInactiveHandler);
1247
 }
1274
 }
1248
 
1275
 
1249
 /**
1276
 /**
1344
     return tracks[0].id;
1371
     return tracks[0].id;
1345
 };
1372
 };
1346
 
1373
 
1374
+/**
1375
+ * Checks whether the MediaStream is avtive/not ended.
1376
+ * When there is no check for active we don't have information and so
1377
+ * will return that stream is active (in case of FF).
1378
+ * @returns {boolean} whether MediaStream is active.
1379
+ */
1380
+JitsiTrack.prototype.isActive = function () {
1381
+    if((typeof this.stream.active !== "undefined"))
1382
+        return this.stream.active;
1383
+    else
1384
+        return true;
1385
+};
1386
+
1387
+
1347
 module.exports = JitsiTrack;
1388
 module.exports = JitsiTrack;
1348
 
1389
 
1349
 },{"./RTCBrowserType":14,"./RTCUtils":15}],13:[function(require,module,exports){
1390
 },{"./RTCBrowserType":14,"./RTCUtils":15}],13:[function(require,module,exports){

Loading…
取消
儲存