diff --git a/e2e/specs/calls/calls_functionality.test.ts b/e2e/specs/calls/calls_functionality.test.ts index 22d96095dbf..4548c3e691b 100644 --- a/e2e/specs/calls/calls_functionality.test.ts +++ b/e2e/specs/calls/calls_functionality.test.ts @@ -7,7 +7,6 @@ import type {ElectronApplication} from 'playwright'; import {test, expect} from '../../fixtures/index'; import {findCallsWidgetWindow, waitForCallsWidgetWindow} from '../../helpers/callsWidget'; import {demoMattermostConfig} from '../../helpers/config'; -import {CALLS_LEAVE_CALL} from '../../helpers/ipcChannels'; import {loginToMattermost} from '../../helpers/login'; import type {ServerView} from '../../helpers/serverView'; @@ -205,9 +204,9 @@ async function closeCallsWidget( }); if (!leaveClicked) { - await electronApp.evaluate(({ipcMain}, channel) => { - ipcMain.emit(channel); - }, CALLS_LEAVE_CALL); + await widgetWindow.evaluate(() => { + (window as unknown as {desktopAPI?: {leaveCall: () => void}}).desktopAPI?.leaveCall(); + }); } await expect.poll( diff --git a/src/app/callsWidgetWindow.test.js b/src/app/callsWidgetWindow.test.js index 732d0794245..ce9066698e5 100644 --- a/src/app/callsWidgetWindow.test.js +++ b/src/app/callsWidgetWindow.test.js @@ -363,6 +363,38 @@ describe('main/windows/callsWidgetWindow', () => { expect(callsWidgetWindow.win.webContents.send).toHaveBeenCalledWith(CALLS_WIDGET_SHARE_SCREEN, 'sourceId', true); }); + describe('handleCallsLeave', () => { + const callsWidgetWindow = new CallsWidgetWindow(); + + beforeEach(() => { + callsWidgetWindow.close = jest.fn(); + callsWidgetWindow.mainView = {webContentsId: 'mainViewID'}; + callsWidgetWindow.win = {webContents: {id: 'widgetID'}, isDestroyed: () => false}; + callsWidgetWindow.popOut = undefined; + }); + + afterEach(() => { + jest.clearAllMocks(); + delete callsWidgetWindow.mainView; + delete callsWidgetWindow.win; + }); + + it('should not close when the sender is a different server', () => { + callsWidgetWindow.handleCallsLeave({sender: {id: 'otherServerID'}}); + expect(callsWidgetWindow.close).not.toHaveBeenCalled(); + }); + + it('should close when the sender is the calls widget', () => { + callsWidgetWindow.handleCallsLeave({sender: {id: 'widgetID'}}); + expect(callsWidgetWindow.close).toHaveBeenCalled(); + }); + + it('should close when the sender is the main view of the call', () => { + callsWidgetWindow.handleCallsLeave({sender: {id: 'mainViewID'}}); + expect(callsWidgetWindow.close).toHaveBeenCalled(); + }); + }); + describe('onPopOutOpen', () => { const callsWidgetWindow = new CallsWidgetWindow(); diff --git a/src/app/callsWidgetWindow.ts b/src/app/callsWidgetWindow.ts index 56ca67a932d..9b708d5bcfd 100644 --- a/src/app/callsWidgetWindow.ts +++ b/src/app/callsWidgetWindow.ts @@ -615,9 +615,14 @@ export class CallsWidgetWindow { return promise; }; - private handleCallsLeave = () => { + private handleCallsLeave = (event: IpcMainEvent) => { log.debug('handleCallsLeave'); + if (!this.isCallsWidget(event.sender.id) && this.mainView?.webContentsId !== event.sender.id) { + log.debug('handleCallsLeave', 'blocked on wrong webContentsId'); + return; + } + this.close(); };