Makes sure we add/remove all onended events for media streams in one central place.
This commit is contained in:
parent
11e1197901
commit
1ba0a182f6
|
@ -39,9 +39,12 @@ function LocalStream(stream, type, eventEmitter, videoType, isGUMStream) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stream.onended = function () {
|
APP.RTC.addMediaStreamInactiveHandler(
|
||||||
self.streamEnded();
|
this.stream,
|
||||||
};
|
function () {
|
||||||
|
self.streamEnded();
|
||||||
|
});
|
||||||
|
|
||||||
if (RTCBrowserType.isFirefox()) {
|
if (RTCBrowserType.isFirefox()) {
|
||||||
implementOnEndedHandling(this.stream);
|
implementOnEndedHandling(this.stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,6 +266,7 @@ var RTC = {
|
||||||
/**
|
/**
|
||||||
* A method to handle stopping of the stream.
|
* A method to handle stopping of the stream.
|
||||||
* One point to handle the differences in various implementations.
|
* One point to handle the differences in various implementations.
|
||||||
|
* @param mediaStream MediaStream object to stop.
|
||||||
*/
|
*/
|
||||||
stopMediaStream: function (mediaStream) {
|
stopMediaStream: function (mediaStream) {
|
||||||
mediaStream.getAudioTracks().forEach(function (track) {
|
mediaStream.getAudioTracks().forEach(function (track) {
|
||||||
|
@ -285,6 +286,36 @@ var RTC = {
|
||||||
if (mediaStream.stop) {
|
if (mediaStream.stop) {
|
||||||
mediaStream.stop();
|
mediaStream.stop();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Adds onended handler to a MediaStream.
|
||||||
|
* @param mediaStream a MediaStream to attach onended handler
|
||||||
|
* @param handler the handler
|
||||||
|
*/
|
||||||
|
addMediaStreamInactiveHandler: function (mediaStream, handler) {
|
||||||
|
if (mediaStream.addEventListener) {
|
||||||
|
// chrome
|
||||||
|
mediaStream.onended = handler;
|
||||||
|
} else {
|
||||||
|
// themasys
|
||||||
|
mediaStream.attachEvent('ended', function () {
|
||||||
|
handler(mediaStream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Removes onended handler.
|
||||||
|
* @param mediaStream the MediaStream to remove the handler from.
|
||||||
|
* @param handler the handler to remove.
|
||||||
|
*/
|
||||||
|
removeMediaStreamInactiveHandler: function (mediaStream, handler) {
|
||||||
|
if (mediaStream.removeEventListener) {
|
||||||
|
// chrome
|
||||||
|
mediaStream.onended = null;
|
||||||
|
} else {
|
||||||
|
// themasys
|
||||||
|
mediaStream.detachEvent('ended', handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -208,13 +208,14 @@ LocalVideo.prototype.changeVideo = function (stream, isMuted) {
|
||||||
APP.RTC.attachMediaStream(localVideoSelector, stream.getOriginalStream());
|
APP.RTC.attachMediaStream(localVideoSelector, stream.getOriginalStream());
|
||||||
|
|
||||||
// Add stream ended handler
|
// Add stream ended handler
|
||||||
stream.getOriginalStream().onended = function () {
|
APP.RTC.addMediaStreamInactiveHandler(
|
||||||
|
stream.getOriginalStream(), function () {
|
||||||
// We have to re-select after attach when Temasys plugin is used,
|
// We have to re-select after attach when Temasys plugin is used,
|
||||||
// because <video> element is replaced with <object>
|
// because <video> element is replaced with <object>
|
||||||
localVideo = $('#' + localVideo.id)[0];
|
localVideo = $('#' + localVideo.id)[0];
|
||||||
localVideoContainer.removeChild(localVideo);
|
localVideoContainer.removeChild(localVideo);
|
||||||
self.VideoLayout.updateRemovedVideo(APP.xmpp.myResource());
|
self.VideoLayout.updateRemovedVideo(APP.xmpp.myResource());
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalVideo.prototype.joined = function (jid) {
|
LocalVideo.prototype.joined = function (jid) {
|
||||||
|
|
|
@ -229,12 +229,12 @@ RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
|
||||||
APP.RTC.attachMediaStream(sel, stream);
|
APP.RTC.attachMediaStream(sel, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.onended = function () {
|
APP.RTC.addMediaStreamInactiveHandler(
|
||||||
console.log('stream ended', this);
|
stream, function () {
|
||||||
|
console.log('stream ended', this);
|
||||||
|
|
||||||
self.removeRemoteStreamElement(stream, isVideo, newElementId);
|
self.removeRemoteStreamElement(stream, isVideo, newElementId);
|
||||||
|
});
|
||||||
};
|
|
||||||
|
|
||||||
// Add click handler.
|
// Add click handler.
|
||||||
var onClickHandler = function (event) {
|
var onClickHandler = function (event) {
|
||||||
|
|
|
@ -54,12 +54,8 @@ function onEndedHandler(stream) {
|
||||||
if (!switchInProgress && isUsingScreenStream) {
|
if (!switchInProgress && isUsingScreenStream) {
|
||||||
APP.desktopsharing.toggleScreenSharing();
|
APP.desktopsharing.toggleScreenSharing();
|
||||||
}
|
}
|
||||||
//FIXME: to be verified
|
|
||||||
if (stream.removeEventListener) {
|
APP.RTC.removeMediaStreamInactiveHandler(stream, onEndedHandler);
|
||||||
stream.removeEventListener('ended', onEndedHandler);
|
|
||||||
} else {
|
|
||||||
stream.detachEvent('ended', onEndedHandler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -113,16 +109,8 @@ module.exports = {
|
||||||
isUsingScreenStream = true;
|
isUsingScreenStream = true;
|
||||||
// Hook 'ended' event to restore camera
|
// Hook 'ended' event to restore camera
|
||||||
// when screen stream stops
|
// when screen stream stops
|
||||||
//FIXME: to be verified
|
APP.RTC.addMediaStreamInactiveHandler(
|
||||||
if (stream.addEventListener) {
|
stream, onEndedHandler);
|
||||||
stream.addEventListener('ended', function () {
|
|
||||||
onEndedHandler(stream);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
stream.attachEvent('ended', function () {
|
|
||||||
onEndedHandler(stream);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
newStreamCreated(stream);
|
newStreamCreated(stream);
|
||||||
},
|
},
|
||||||
getDesktopStreamFailed);
|
getDesktopStreamFailed);
|
||||||
|
|
Loading…
Reference in New Issue