diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index 79d212f21..15d6641b2 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -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(); diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 4b1a81839..081f3ef2f 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -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) { diff --git a/modules/connectionquality/connectionquality.js b/modules/connectionquality/connectionquality.js index 4e2cb742f..c8b381dfe 100644 --- a/modules/connectionquality/connectionquality.js +++ b/modules/connectionquality/connectionquality.js @@ -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; \ No newline at end of file +module.exports = ConnectionQuality; diff --git a/modules/desktopsharing/desktopsharing.js b/modules/desktopsharing/desktopsharing.js index f245252ed..b46f9b3ee 100644 --- a/modules/desktopsharing/desktopsharing.js +++ b/modules/desktopsharing/desktopsharing.js @@ -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); }, diff --git a/modules/statistics/LocalStatsCollector.js b/modules/statistics/LocalStatsCollector.js index b8f624335..32e572079 100644 --- a/modules/statistics/LocalStatsCollector.js +++ b/modules/statistics/LocalStatsCollector.js @@ -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; diff --git a/modules/xmpp/moderator.js b/modules/xmpp/moderator.js index 8d355d343..082f0aaab 100644 --- a/modules/xmpp/moderator.js +++ b/modules/xmpp/moderator.js @@ -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); }, diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js index 0e90713d2..e35d25cae 100644 --- a/modules/xmpp/xmpp.js +++ b/modules/xmpp/xmpp.js @@ -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