From 562ef14aeff6f0d8a3992ba79190ea232b22c51b Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Fri, 10 Feb 2023 11:13:31 -0600 Subject: [PATCH] Fix media permissions failure on Calls window (#2550) --- src/main/windows/callsWidgetWindow.test.js | 21 +++++++++++++++ src/main/windows/callsWidgetWindow.ts | 9 +++++++ src/main/windows/windowManager.test.js | 31 ++++++++++++++++++++++ src/main/windows/windowManager.ts | 4 +++ 4 files changed, 65 insertions(+) diff --git a/src/main/windows/callsWidgetWindow.test.js b/src/main/windows/callsWidgetWindow.test.js index 369f973c..339c4f41 100644 --- a/src/main/windows/callsWidgetWindow.test.js +++ b/src/main/windows/callsWidgetWindow.test.js @@ -358,5 +358,26 @@ describe('main/windows/callsWidgetWindow', () => { expect(popOut.focus).toHaveBeenCalled(); expect(popOut.restore).toHaveBeenCalled(); }); + + it('getWebContentsId', () => { + baseWindow.webContents = { + ...baseWindow.webContents, + id: 'testID', + }; + + const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig); + expect(widgetWindow.getWebContentsId()).toBe('testID'); + }); + + it('getURL', () => { + baseWindow.webContents = { + ...baseWindow.webContents, + id: 'testID', + getURL: jest.fn(() => 'http://localhost:8065/'), + }; + + const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig); + expect(widgetWindow.getURL().toString()).toBe('http://localhost:8065/'); + }); }); }); diff --git a/src/main/windows/callsWidgetWindow.ts b/src/main/windows/callsWidgetWindow.ts index 081b4982..2d426a4e 100644 --- a/src/main/windows/callsWidgetWindow.ts +++ b/src/main/windows/callsWidgetWindow.ts @@ -24,6 +24,7 @@ import { CALLS_PLUGIN_ID, } from 'common/utils/constants'; import Utils from 'common/utils/util'; +import urlUtils from 'common/utils/url'; import { CALLS_JOINED_CALL, CALLS_POPOUT_FOCUS, @@ -210,5 +211,13 @@ export default class CallsWidgetWindow extends EventEmitter { } this.popOut.focus(); } + + public getWebContentsId() { + return this.win.webContents.id; + } + + public getURL() { + return urlUtils.parseURL(this.win.webContents.getURL()); + } } diff --git a/src/main/windows/windowManager.test.js b/src/main/windows/windowManager.test.js index 77751b2f..1e252fe4 100644 --- a/src/main/windows/windowManager.test.js +++ b/src/main/windows/windowManager.test.js @@ -1183,4 +1183,35 @@ describe('main/windows/windowManager', () => { expect(windowManager.switchServer).toHaveBeenCalledWith('server-2'); }); }); + + describe('getServerURLFromWebContentsId', () => { + const view = { + name: 'server-1_tab-messaging', + serverInfo: { + remoteInfo: { + siteURL: 'http://server-1.com', + }, + }, + }; + const windowManager = new WindowManager(); + windowManager.viewManager = { + views: new Map([ + ['server-1_tab-messaging', view], + ]), + findViewByWebContent: jest.fn(), + }; + + it('should return calls widget URL', () => { + CallsWidgetWindow.mockImplementation(() => { + return { + on: jest.fn(), + getURL: jest.fn(() => 'http://localhost:8065'), + getWebContentsId: jest.fn(() => 'callsID'), + }; + }); + + windowManager.createCallsWidgetWindow(null, 'server-1_tab-messaging', {callID: 'test'}); + expect(windowManager.getServerURLFromWebContentsId('callsID')).toBe(windowManager.callsWidgetWindow.getURL()); + }); + }); }); diff --git a/src/main/windows/windowManager.ts b/src/main/windows/windowManager.ts index 317b560a..e8e54a1a 100644 --- a/src/main/windows/windowManager.ts +++ b/src/main/windows/windowManager.ts @@ -862,6 +862,10 @@ export class WindowManager { } getServerURLFromWebContentsId = (id: number) => { + if (this.callsWidgetWindow && id === this.callsWidgetWindow.getWebContentsId()) { + return this.callsWidgetWindow.getURL(); + } + const viewName = this.getViewNameByWebContentsId(id); if (!viewName) { return undefined;