Makes sure we add/remove all onended events for media streams in one central place.
This commit is contained in:
parent
9e119be441
commit
02c7844307
|
@ -9,17 +9,18 @@ var RTCBrowserType = require("./RTCBrowserType");
|
|||
function JitsiLocalTrack(RTC, stream, eventEmitter, videoType,
|
||||
resolution)
|
||||
{
|
||||
JitsiTrack.call(this, RTC, stream);
|
||||
JitsiTrack.call(this, RTC, stream,
|
||||
function () {
|
||||
if(!self.dontFireRemoveEvent)
|
||||
self.eventEmitter.emit(
|
||||
StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
|
||||
self.dontFireRemoveEvent = false;
|
||||
});
|
||||
this.eventEmitter = eventEmitter;
|
||||
this.videoType = videoType;
|
||||
this.dontFireRemoveEvent = false;
|
||||
this.resolution = resolution;
|
||||
var self = this;
|
||||
this.stream.onended = function () {
|
||||
if(!self.dontFireRemoveEvent)
|
||||
self.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
|
||||
self.dontFireRemoveEvent = false;
|
||||
};
|
||||
}
|
||||
|
||||
JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
|
||||
|
|
|
@ -11,7 +11,10 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
|
|||
* @constructor
|
||||
*/
|
||||
function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
|
||||
JitsiTrack.call(this, RTC, data.stream);
|
||||
JitsiTrack.call(this, RTC, data.stream,
|
||||
function () {
|
||||
eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, self);
|
||||
});
|
||||
this.rtc = RTC;
|
||||
this.sid = sid;
|
||||
this.stream = data.stream;
|
||||
|
@ -25,10 +28,6 @@ function JitsiRemoteTrack(RTC, data, sid, ssrc, eventEmitter) {
|
|||
}
|
||||
this.eventEmitter = eventEmitter;
|
||||
var self = this;
|
||||
if(this.stream)
|
||||
this.stream.onended = function () {
|
||||
eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, self);
|
||||
}
|
||||
}
|
||||
|
||||
JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
|
||||
|
|
|
@ -17,11 +17,35 @@ function implementOnEndedHandling(stream) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds onended/oninactive handler to a MediaStream.
|
||||
* @param mediaStream a MediaStream to attach onended/oninactive handler
|
||||
* @param handler the handler
|
||||
*/
|
||||
function addMediaStreamInactiveHandler(mediaStream, handler) {
|
||||
if (mediaStream.addEventListener) {
|
||||
// chrome
|
||||
if(typeof mediaStream.active !== "undefined")
|
||||
mediaStream.oninactive = handler;
|
||||
else
|
||||
mediaStream.onended = handler;
|
||||
} else {
|
||||
// themasys
|
||||
mediaStream.attachEvent('ended', function () {
|
||||
handler(mediaStream);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a single media track (either audio or video).
|
||||
* @constructor
|
||||
* @param rtc the rtc instance
|
||||
* @param stream the stream
|
||||
* @param streamInactiveHandler the function that will handle
|
||||
* onended/oninactive events of the stream.
|
||||
*/
|
||||
function JitsiTrack(rtc, stream)
|
||||
function JitsiTrack(rtc, stream, streamInactiveHandler)
|
||||
{
|
||||
/**
|
||||
* Array with the HTML elements that are displaying the streams.
|
||||
|
@ -44,6 +68,9 @@ function JitsiTrack(rtc, stream)
|
|||
if (RTCBrowserType.isFirefox() && this.stream) {
|
||||
implementOnEndedHandling(this.stream);
|
||||
}
|
||||
|
||||
if(stream)
|
||||
addMediaStreamInactiveHandler(stream, streamInactiveHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue