[MM-50995] Harden Calls events handling (#2571)
* Simplify server switching logic in calls events * Harden calls events handling * Fix subpath
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
CallsJoinCallMessage,
|
||||
CallsErrorMessage,
|
||||
CallsLinkClickMessage,
|
||||
CallsEventHandler,
|
||||
} from 'types/calls';
|
||||
|
||||
import {
|
||||
@@ -97,15 +98,17 @@ export class WindowManager {
|
||||
ipcMain.on(APP_LOGGED_OUT, this.handleAppLoggedOut);
|
||||
ipcMain.handle(GET_VIEW_NAME, this.handleGetViewName);
|
||||
ipcMain.handle(GET_VIEW_WEBCONTENTS_ID, this.handleGetWebContentsId);
|
||||
ipcMain.on(DISPATCH_GET_DESKTOP_SOURCES, this.handleGetDesktopSources);
|
||||
ipcMain.on(RELOAD_CURRENT_VIEW, this.handleReloadCurrentView);
|
||||
ipcMain.on(VIEW_FINISHED_RESIZING, this.handleViewFinishedResizing);
|
||||
ipcMain.on(CALLS_JOIN_CALL, this.createCallsWidgetWindow);
|
||||
ipcMain.on(CALLS_LEAVE_CALL, () => this.callsWidgetWindow?.close());
|
||||
ipcMain.on(DESKTOP_SOURCES_MODAL_REQUEST, this.handleDesktopSourcesModalRequest);
|
||||
ipcMain.on(CALLS_WIDGET_CHANNEL_LINK_CLICK, this.handleCallsWidgetChannelLinkClick);
|
||||
ipcMain.on(CALLS_ERROR, this.handleCallsError);
|
||||
ipcMain.on(CALLS_LINK_CLICK, this.handleCallsLinkClick);
|
||||
|
||||
// Calls handlers
|
||||
ipcMain.on(DISPATCH_GET_DESKTOP_SOURCES, this.genCallsEventHandler(this.handleGetDesktopSources));
|
||||
ipcMain.on(DESKTOP_SOURCES_MODAL_REQUEST, this.genCallsEventHandler(this.handleDesktopSourcesModalRequest));
|
||||
ipcMain.on(CALLS_JOIN_CALL, this.genCallsEventHandler(this.createCallsWidgetWindow));
|
||||
ipcMain.on(CALLS_LEAVE_CALL, this.genCallsEventHandler(this.handleCallsLeave));
|
||||
ipcMain.on(CALLS_WIDGET_CHANNEL_LINK_CLICK, this.genCallsEventHandler(this.handleCallsWidgetChannelLinkClick));
|
||||
ipcMain.on(CALLS_ERROR, this.genCallsEventHandler(this.handleCallsError));
|
||||
ipcMain.on(CALLS_LINK_CLICK, this.genCallsEventHandler(this.handleCallsLinkClick));
|
||||
}
|
||||
|
||||
handleUpdateConfig = () => {
|
||||
@@ -114,7 +117,17 @@ export class WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
createCallsWidgetWindow = (event: IpcMainEvent, viewName: string, msg: CallsJoinCallMessage) => {
|
||||
genCallsEventHandler = (handler: CallsEventHandler) => {
|
||||
return (event: IpcMainEvent, viewName: string, msg?: any) => {
|
||||
if (this.callsWidgetWindow && !this.callsWidgetWindow.isAllowedEvent(event)) {
|
||||
log.warn('WindowManager.genCallsEventHandler', 'Disallowed calls event');
|
||||
return;
|
||||
}
|
||||
handler(viewName, msg);
|
||||
};
|
||||
}
|
||||
|
||||
createCallsWidgetWindow = (viewName: string, msg: CallsJoinCallMessage) => {
|
||||
log.debug('WindowManager.createCallsWidgetWindow');
|
||||
if (this.callsWidgetWindow) {
|
||||
// trying to join again the call we are already in should not be allowed.
|
||||
@@ -130,10 +143,8 @@ export class WindowManager {
|
||||
}
|
||||
|
||||
this.callsWidgetWindow = new CallsWidgetWindow(this.mainWindow!, currentView, {
|
||||
siteURL: currentView.serverInfo.remoteInfo.siteURL!,
|
||||
callID: msg.callID,
|
||||
title: msg.title,
|
||||
serverName: this.currentServerName!,
|
||||
channelURL: msg.channelURL,
|
||||
});
|
||||
|
||||
@@ -146,23 +157,23 @@ export class WindowManager {
|
||||
if (this.callsWidgetWindow) {
|
||||
this.switchServer(this.callsWidgetWindow.getServerName());
|
||||
this.mainWindow?.focus();
|
||||
const currentView = this.viewManager?.getCurrentView();
|
||||
currentView?.view.webContents.send(DESKTOP_SOURCES_MODAL_REQUEST);
|
||||
this.callsWidgetWindow.getMainView().view.webContents.send(DESKTOP_SOURCES_MODAL_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
handleCallsWidgetChannelLinkClick = () => {
|
||||
log.debug('WindowManager.handleCallsWidgetChannelLinkClick');
|
||||
|
||||
if (this.callsWidgetWindow) {
|
||||
this.switchServer(this.callsWidgetWindow.getServerName());
|
||||
this.mainWindow?.focus();
|
||||
const currentView = this.viewManager?.getCurrentView();
|
||||
currentView?.view.webContents.send(BROWSER_HISTORY_PUSH, this.callsWidgetWindow.getChannelURL());
|
||||
this.callsWidgetWindow.getMainView().view.webContents.send(BROWSER_HISTORY_PUSH, this.callsWidgetWindow.getChannelURL());
|
||||
}
|
||||
}
|
||||
|
||||
handleCallsError = (event: IpcMainEvent, msg: CallsErrorMessage) => {
|
||||
handleCallsError = (_: string, msg: CallsErrorMessage) => {
|
||||
log.debug('WindowManager.handleCallsError', msg);
|
||||
|
||||
if (this.callsWidgetWindow) {
|
||||
this.switchServer(this.callsWidgetWindow.getServerName());
|
||||
this.mainWindow?.focus();
|
||||
@@ -170,11 +181,20 @@ export class WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
handleCallsLinkClick = (_: IpcMainEvent, msg: CallsLinkClickMessage) => {
|
||||
handleCallsLinkClick = (_: string, msg: CallsLinkClickMessage) => {
|
||||
log.debug('WindowManager.handleCallsLinkClick with linkURL', msg.link);
|
||||
this.mainWindow?.focus();
|
||||
const currentView = this.viewManager?.getCurrentView();
|
||||
currentView?.view.webContents.send(BROWSER_HISTORY_PUSH, msg.link);
|
||||
|
||||
if (this.callsWidgetWindow) {
|
||||
this.switchServer(this.callsWidgetWindow.getServerName());
|
||||
this.mainWindow?.focus();
|
||||
this.callsWidgetWindow.getMainView().view.webContents.send(BROWSER_HISTORY_PUSH, msg.link);
|
||||
}
|
||||
}
|
||||
|
||||
handleCallsLeave = () => {
|
||||
log.debug('WindowManager.handleCallsLeave');
|
||||
|
||||
this.callsWidgetWindow?.close();
|
||||
}
|
||||
|
||||
showSettingsWindow = () => {
|
||||
@@ -850,7 +870,7 @@ export class WindowManager {
|
||||
return event.sender.id;
|
||||
}
|
||||
|
||||
handleGetDesktopSources = async (event: IpcMainEvent, viewName: string, opts: Electron.SourcesOptions) => {
|
||||
handleGetDesktopSources = async (viewName: string, opts: Electron.SourcesOptions) => {
|
||||
log.debug('WindowManager.handleGetDesktopSources', {viewName, opts});
|
||||
|
||||
const view = this.viewManager?.views.get(viewName);
|
||||
|
Reference in New Issue
Block a user