From 26a6d2bbaec2ef113acb188dae194162a4f11bdd Mon Sep 17 00:00:00 2001 From: hristoterezov <hristo@jitsi.org> Date: Thu, 5 Jan 2017 19:19:53 -0600 Subject: [PATCH] fix(): Issues related to requesting permissions --- modules/remotecontrol/index.js | 17 ++++++++++++++--- windows/jitsi-meet/render.js | 33 ++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/modules/remotecontrol/index.js b/modules/remotecontrol/index.js index ca7501a..8263005 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 a983d86..b4d83a0 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(); +} -- GitLab