Skip to content

Commit

Permalink
fix(SS): when the iframe reloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
hristoterezov committed Jun 7, 2021
1 parent 5901f4f commit 8c6e80a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jitsi-meet-electron-utils",
"version": "2.0.20",
"version": "2.0.21",
"description": "Utilities for jitsi-meet-electron project",
"main": "index.js",
"scripts": {
Expand Down
37 changes: 26 additions & 11 deletions screensharing/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ class ScreenShareRenderHook {
this._sendCloseTrackerEvent = this._sendCloseTrackerEvent.bind(this);
this._onScreenSharingEvent = this._onScreenSharingEvent.bind(this);
this._onIframeApiLoad = this._onIframeApiLoad.bind(this);
this._cleanContext = this._cleanContext.bind(this);
this._cleanTrackerContext = this._cleanTrackerContext.bind(this);
this._onApiDispose = this._onApiDispose.bind(this);

ipcRenderer.on(SCREEN_SHARE_EVENTS_CHANNEL, this._onScreenSharingEvent);
this._api.on('screenSharingStatusChanged', this._onScreenSharingStatusChanged);
this._api.on('videoConferenceLeft', this._cleanContext);
this._api.on('_willDispose', this._cleanContext);
this._api.on('_willDispose', this._onApiDispose);
this._iframe.addEventListener('load', this._onIframeApiLoad);
}

Expand Down Expand Up @@ -59,6 +57,10 @@ class ScreenShareRenderHook {
.catch((error) => errorCallback(error));
}
};

ipcRenderer.on(SCREEN_SHARE_EVENTS_CHANNEL, this._onScreenSharingEvent);
this._api.on('screenSharingStatusChanged', this._onScreenSharingStatusChanged);
this._api.on('videoConferenceLeft', this._cleanTrackerContext);
}

/**
Expand Down Expand Up @@ -121,19 +123,32 @@ class ScreenShareRenderHook {
}

/**
* Clear all event handler in order to avoid any potential leaks and close the screen sharing tracker
* window in the event that it's currently being displayed.
* Clear all event handlers related to the tracker in order to avoid any potential leaks and closes it in the event
* that it's currently being displayed.
*
* @returns {void}
*/
_cleanContext() {
_cleanTrackerContext() {
ipcRenderer.removeListener(SCREEN_SHARE_EVENTS_CHANNEL, this._onScreenSharingEvent);
this._api.removeListener('screenSharingStatusChanged', this._onScreenSharingStatusChanged);
this._api.removeListener('videoConferenceLeft', this._sendCloseTrackerEvent);
this._api.removeListener('_willDispose', this._sendCloseTrackerEvent);
this._iframe.removeEventListener('load', this._onIframeApiLoad);
this._api.removeListener('videoConferenceLeft', this._cleanTrackerContext);
this._sendCloseTrackerEvent();
}

/**
* Clear all event handlers in order to avoid any potential leaks.
*
* NOTE: It is very important to remove the load listener only when we are sure that the iframe won't be used
* anymore. Otherwise if we use the videoConferenceLeft event for example, when the iframe is internally reloaded
* because of an error and then loads again we won't initialize the screen sharing functionality.
*
* @returns {void}
*/
_onApiDispose() {
this._cleanTrackerContext();
this._api.removeListener('_willDispose', this._onApiDispose);
this._iframe.removeEventListener('load', this._onIframeApiLoad);
}
}

/**
Expand Down

0 comments on commit 8c6e80a

Please sign in to comment.