diff --git a/modules/remotecontrol/index.js b/modules/remotecontrol/index.js index ca7501a767502cb7786c1cb5c7017e44f2ded2c4..82630057388db45b651c1531eb37dea2a460f19c 100644 --- a/modules/remotecontrol/index.js +++ b/modules/remotecontrol/index.js @@ -67,7 +67,6 @@ class RemoteControl { init(channel, windowManager) { this.windowManager = windowManager; this.channel = channel; - this.start(); this.channel.ready(() => { this.channel.listen(REMOTE_CONTROL_EVENT_TYPE, event => this.onRemoteControlEvent(event)); @@ -75,6 +74,15 @@ class RemoteControl { }); } + /** + * Disposes the remote control functionality. + */ + dispose() { + this.windowManager = null; + this.channel = null; + this.stop(); + } + /** * Handles permission requests from Jitsi Meet. * @param {object} userInfo - information about the user that has requested @@ -82,6 +90,8 @@ class RemoteControl { * @param {string} userInfo.displayName - display name * @param {string} userInfo.userJID - the JID of the user. * @param {string} userInfo.userId - the user id (the resource of the JID) + * @param {boolean} userInfo.screenSharing - true if the screen sharing + * is started. */ handlePermissionRequest(userInfo) { this.windowManager.requestRemoteControlPermissions(userInfo) @@ -119,7 +129,6 @@ class RemoteControl { * @param {Object} event the remote-control-event. */ onRemoteControlEvent(event) { - if(!this.started && event.type !== EVENT_TYPES.permissions) { return; } @@ -171,7 +180,9 @@ class RemoteControl { this.handlePermissionRequest({ userId: event.userId, userJID: event.userJID, - displayName: event.displayName}); + displayName: event.displayName, + screenSharing: event.screenSharing + }); break; } case EVENT_TYPES.stop: { diff --git a/windows/jitsi-meet/render.js b/windows/jitsi-meet/render.js index a983d863c9193b1d69f19f07c0fa84912ec80a11..b4d83a0e93ecef43033edec62cd4e3645f8f0705 100644 --- a/windows/jitsi-meet/render.js +++ b/windows/jitsi-meet/render.js @@ -34,16 +34,24 @@ class DialogFactory { * request: * @param {string} userInfo.displayName - display name * @param {string} userInfo.userJID - the JID of the user. + * @param {boolean} userInfo.screenSharing - true if the screen sharing + * is started. */ requestRemoteControlPermissions(userInfo) { return new Promise( resolve => dialog.showMessageBox({ type: "question", - buttons: ["Yes", "No"], + buttons: [ + "Yes", + "No" + ], defaultId: 0, title: "Request for permission for remote control", message: "Would you like to allow " + userInfo.displayName - + " to remotely control your desktop.", + + " to remotely control your desktop?" + + (userInfo.screenSharing ? "" + : "\nNote: If you press \"Yes\" the screen sharing " + + "will start!"), detail: "userId: " + userInfo.userJID, cancelId: 1 }, response => resolve(response === 0? true : false)) @@ -56,13 +64,6 @@ class DialogFactory { */ const dialogFactory = new DialogFactory(); -/** - * Boolean variable that indicates whether the onloaded function was already - * called. - * NOTE: Used to not initialize more thean once some objects. - */ -let loaded = false; - /** * Handles loaded event for iframe: * Enables screen sharing functionality to the iframe webpage. @@ -70,14 +71,20 @@ let loaded = false; * Initializes remote control. */ function onload() { - loaded = true; setupScreenSharingForWindow(iframe.contentWindow); - if(loaded) { - return; - } + iframe.contentWindow.onunload = onunload; channel = postis({ window: iframe.contentWindow, windowForEventListening: window }); remoteControl.init(channel, dialogFactory); } + +/** + * Clears the postis objects and remoteControl. + */ +function onunload() { + channel.destroy(); + channel = null; + remoteControl.dispose(); +}