Updates to add removelisteners to classes so that event listeners can be unregistered

This commit is contained in:
Brad Beeler 2015-10-02 11:43:41 -06:00 committed by Mike Girard
parent 1b4052137f
commit c4258791c5
7 changed files with 48 additions and 15 deletions

View File

@ -62,6 +62,9 @@ var RTC = {
addListener: function (type, listener) {
eventEmitter.on(type, listener);
},
removeListener: function(type, listener){
eventEmitter.removeListener(type, listener);
},
removeStreamListener: function (listener, eventType) {
if(!(eventType instanceof StreamEventTypes))
throw "Illegal argument";
@ -146,9 +149,16 @@ var RTC = {
return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
},
dispose: function() {
APP.UI.removeListener(UIEvents.SELECTED_ENDPOINT,
DataChannels.handleSelectedEndpointEvent);
APP.UI.removeListener(UIEvents.PINNED_ENDPOINT,
DataChannels.handlePinnedEndpointEvent);
if (this.rtcUtils) {
this.rtcUtils = null;
}
if (eventEmitter) {
eventEmitter.removeAllListeners();
}
},
stop: function () {
this.dispose();

View File

@ -877,6 +877,10 @@ UI.addListener = function (type, listener) {
eventEmitter.on(type, listener);
};
UI.removeListener = function (type, listener) {
eventEmitter.removeListener(type,listener);
};
UI.clickOnVideo = function (videoNumber) {
var remoteVideos = $(".videocontainer:not(#mixedstream)");
if (remoteVideos.length > videoNumber) {

View File

@ -127,11 +127,15 @@ var ConnectionQuality = {
getStats: function () {
return stats;
},
addListener: function (type, listener) {
eventEmitter.on(type, listener);
},
removeListener: function (type, listener) {
eventEmitter.removeListener(type, listener);
}
};
module.exports = ConnectionQuality;
module.exports = ConnectionQuality;

View File

@ -60,6 +60,11 @@ function onEndedHandler(stream) {
APP.RTC.removeMediaStreamInactiveHandler(stream, onEndedHandler);
}
function initScreenObtainer() {
screenObtainer.init(eventEmitter);
eventEmitter.emit(DesktopSharingEventTypes.INIT);
}
module.exports = {
isUsingScreenStream: function () {
return isUsingScreenStream;
@ -72,17 +77,18 @@ module.exports = {
isDesktopSharingEnabled: function () {
return screenObtainer.isSupported();
},
init: function () {
// Called when RTC finishes initialization
APP.RTC.addListener(RTCEvents.RTC_READY,
function() {
screenObtainer.init(eventEmitter);
eventEmitter.emit(DesktopSharingEventTypes.INIT);
});
APP.RTC.addListener(RTCEvents.RTC_READY, initScreenObtainer);
},
addListener: function (type, listener) {
destroy: function() {
APP.RTC.removeListener(RTCEvents.RTC_READY, initScreenObtainer);
eventEmitter.removeAllListeners();
},
addListener: function (type, listener)
{
eventEmitter.on(type, listener);
},

View File

@ -87,7 +87,12 @@ LocalStatsCollector.prototype.start = function () {
RTCBrowserType.isTemasysPluginUsed())
return;
this.context = new AudioContext();
try {
this.context = new AudioContext();
}
catch(ex) {
console.warn("WARNING: Could not create AudioContext " + ex);
}
var analyser = this.context.createAnalyser();
analyser.smoothingTimeConstant = WEBAUDIO_ANALYZER_SMOOTING_TIME;
analyser.fftSize = WEBAUDIO_ANALYZER_FFT_SIZE;
@ -125,7 +130,8 @@ LocalStatsCollector.prototype.stop = function () {
this.intervalId = null;
}
// Clean up context
if (this.context && this.context.close && typeof this.context.close === 'function') {
if (this.context && this.context.close &&
typeof this.context.close === 'function') {
this.context.close();
}
this.context = undefined;

View File

@ -35,7 +35,7 @@ var externalAuthEnabled = false;
// Sip gateway can be enabled by configuring Jigasi host in config.js or
// it will be enabled automatically if focus detects the component through
// service discovery.
var sipGatewayEnabled;
var sipGatewayEnabled = false;
var eventEmitter = null;
@ -100,7 +100,7 @@ var Moderator = {
location.reload();
}
},
setFocusUserJid: function (focusJid) {
if (!focusUserJid) {
focusUserJid = focusJid;
@ -245,7 +245,7 @@ var Moderator = {
eventEmitter.emit(AuthenticationEvents.IDENTITY_UPDATED,
authenticationEnabled, authIdentity);
// Check if focus has auto-detected Jigasi component(this will be also
// included if we have passed our host from the config)
if ($(resultIq).find(
@ -253,7 +253,7 @@ var Moderator = {
'[name=\'sipGatewayEnabled\'][value=\'true\']').length) {
sipGatewayEnabled = true;
}
console.info("Sip gateway enabled: " + sipGatewayEnabled);
},

View File

@ -319,6 +319,9 @@ var XMPP = {
}
connect(jid, password);
},
stop: function () {
eventEmitter.removeAllListeners();
},
createConnection: function () {
var bosh = config.bosh || '/http-bind';
// adds the room name used to the bosh connection