Ver código fonte

Updates latest changes.

dev1
damencho 10 anos atrás
pai
commit
562e57fe96
1 arquivos alterados com 60 adições e 19 exclusões
  1. 60
    19
      lib-jitsi-meet.js

+ 60
- 19
lib-jitsi-meet.js Ver arquivo

@@ -987,17 +987,18 @@ var RTCBrowserType = require("./RTCBrowserType");
987 987
 function JitsiLocalTrack(RTC, stream, eventEmitter, videoType,
988 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 997
     this.eventEmitter = eventEmitter;
992 998
     this.videoType = videoType;
993 999
     this.dontFireRemoveEvent = false;
994 1000
     this.resolution = resolution;
995 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 1004
 JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
@@ -1107,7 +1108,7 @@ JitsiLocalTrack.prototype.isMuted = function () {
1107 1108
     if (isAudio) {
1108 1109
         tracks = this.stream.getAudioTracks();
1109 1110
     } else {
1110
-        if (this.stream.ended)
1111
+        if (!this.isActive())
1111 1112
             return true;
1112 1113
         tracks = this.stream.getVideoTracks();
1113 1114
     }
@@ -1142,7 +1143,10 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
1142 1143
  * @constructor
1143 1144
  */
1144 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 1150
     this.rtc = RTC;
1147 1151
     this.sid = sid;
1148 1152
     this.stream = data.stream;
@@ -1156,10 +1160,6 @@ function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
1156 1160
     }
1157 1161
     this.eventEmitter = eventEmitter;
1158 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 1165
 JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
@@ -1203,25 +1203,49 @@ var RTCBrowserType = require("./RTCBrowserType");
1203 1203
 /**
1204 1204
  * This implements 'onended' callback normally fired by WebRTC after the stream
1205 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 1211
     var originalStop = stream.stop;
1211 1212
     stream.stop = function () {
1212 1213
         originalStop.apply(stream);
1213
-        if (!stream.ended) {
1214
-            stream.ended = true;
1214
+        if (jitsiTrack.isActive()) {
1215 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 1241
  * Represents a single media track (either audio or video).
1222 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 1251
      * Array with the HTML elements that are displaying the streams.
@@ -1242,8 +1266,11 @@ function JitsiTrack(rtc, stream)
1242 1266
         }.bind(this);
1243 1267
     }
1244 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,6 +1371,20 @@ JitsiTrack.prototype.getId = function () {
1344 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 1388
 module.exports = JitsiTrack;
1348 1389
 
1349 1390
 },{"./RTCBrowserType":14,"./RTCUtils":15}],13:[function(require,module,exports){

Carregando…
Cancelar
Salvar