MM-52857 - Add call-join-request to calls widget (#2751)

* add call-join-request to calls widget

* targetID -> callID

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Christopher Poile
2023-06-26 10:17:47 -04:00
committed by GitHub
parent 850573326c
commit 0728ddf42f
6 changed files with 71 additions and 2 deletions

View File

@@ -130,6 +130,7 @@ export const CALLS_LINK_CLICK = 'calls-link-click';
export const CALLS_JOINED_CALL = 'calls-joined-call';
export const CALLS_POPOUT_FOCUS = 'calls-popout-focus';
export const CALLS_ERROR = 'calls-error';
export const CALLS_JOIN_REQUEST = 'calls-join-request';
export const REQUEST_CLEAR_DOWNLOADS_DROPDOWN = 'request-clear-downloads-dropdown';
export const CLOSE_DOWNLOADS_DROPDOWN = 'close-downloads-dropdown';

View File

@@ -16,8 +16,12 @@ import {
DESKTOP_SOURCES_RESULT,
DESKTOP_SOURCES_MODAL_REQUEST,
CALLS_LINK_CLICK,
CALLS_JOIN_REQUEST,
} from 'common/communication';
//
// Handle messages FROM the widget. (i.e., widget's webapp -> widget's window)
//
window.addEventListener('message', ({origin, data = {}} = {}) => {
const {type, message = {}} = data;
@@ -48,13 +52,17 @@ window.addEventListener('message', ({origin, data = {}} = {}) => {
case CALLS_JOINED_CALL:
case CALLS_POPOUT_FOCUS:
case CALLS_ERROR:
case CALLS_LEAVE_CALL: {
case CALLS_LEAVE_CALL:
case CALLS_JOIN_REQUEST: {
ipcRenderer.send(type, 'widget', message);
break;
}
}
});
//
// Handle messages TO the widget.
//
ipcRenderer.on(DESKTOP_SOURCES_RESULT, (event, sources) => {
window.postMessage(
{

View File

@@ -36,6 +36,7 @@ import {
CALLS_WIDGET_SHARE_SCREEN,
CLOSE_DOWNLOADS_DROPDOWN,
CALLS_ERROR,
CALLS_JOIN_REQUEST,
} from 'common/communication';
const UNREAD_COUNT_INTERVAL = 1000;
@@ -352,6 +353,16 @@ ipcRenderer.on(CALLS_ERROR, (event, message) => {
);
});
ipcRenderer.on(CALLS_JOIN_REQUEST, (event, message) => {
window.postMessage(
{
type: CALLS_JOIN_REQUEST,
message,
},
window.location.origin,
);
});
/* eslint-enable no-magic-numbers */
window.addEventListener('resize', () => {

View File

@@ -7,7 +7,7 @@ import {BrowserWindow, desktopCapturer, systemPreferences} from 'electron';
import ServerViewState from 'app/serverViewState';
import {CALLS_WIDGET_SHARE_SCREEN, CALLS_JOINED_CALL} from 'common/communication';
import {CALLS_WIDGET_SHARE_SCREEN, CALLS_JOINED_CALL, CALLS_JOIN_REQUEST} from 'common/communication';
import {
MINIMUM_CALLS_WIDGET_WIDTH,
MINIMUM_CALLS_WIDGET_HEIGHT,
@@ -958,4 +958,35 @@ describe('main/windows/callsWidgetWindow', () => {
expect(handler).toHaveBeenCalledTimes(1);
});
});
describe('handleCallsJoinRequest', () => {
const view = {
view: {
server: {
id: 'server-1',
},
},
sendToRenderer: jest.fn(),
};
const callsWidgetWindow = new CallsWidgetWindow();
callsWidgetWindow.mainView = view;
const focus = jest.fn();
beforeEach(() => {
MainWindow.get.mockReturnValue({focus});
ViewManager.getView.mockReturnValue(view);
});
afterEach(() => {
jest.resetAllMocks();
});
it('should pass through the join call callID to the webapp', () => {
callsWidgetWindow.handleCallsJoinRequest('', {callID: 'thecallchannelid'});
expect(ServerViewState.switchServer).toHaveBeenCalledWith('server-1');
expect(focus).toHaveBeenCalled();
expect(view.sendToRenderer).toBeCalledWith(CALLS_JOIN_REQUEST, {callID: 'thecallchannelid'});
});
});
});

View File

@@ -8,6 +8,7 @@ import {
CallsEventHandler,
CallsJoinCallMessage,
CallsJoinedCallMessage,
CallsJoinRequestMessage,
CallsLinkClickMessage,
CallsWidgetResizeMessage,
CallsWidgetShareScreenMessage,
@@ -24,6 +25,7 @@ import {
BROWSER_HISTORY_PUSH,
CALLS_ERROR,
CALLS_JOIN_CALL,
CALLS_JOIN_REQUEST,
CALLS_JOINED_CALL,
CALLS_LEAVE_CALL,
CALLS_LINK_CLICK,
@@ -75,6 +77,7 @@ export class CallsWidgetWindow {
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));
ipcMain.on(CALLS_JOIN_REQUEST, this.genCallsEventHandler(this.handleCallsJoinRequest));
}
/**
@@ -530,6 +533,17 @@ export class CallsWidgetWindow {
MainWindow.get()?.focus();
this.mainView?.sendToRenderer(BROWSER_HISTORY_PUSH, msg.link);
}
private handleCallsJoinRequest = (_: string, msg: CallsJoinRequestMessage) => {
log.debug('handleCallsJoinRequest with callID', msg.callID);
if (!this.serverID) {
return;
}
ServerViewState.switchServer(this.serverID);
MainWindow.get()?.focus();
this.mainView?.sendToRenderer(CALLS_JOIN_REQUEST, msg);
}
}
const callsWidgetWindow = new CallsWidgetWindow();

View File

@@ -34,4 +34,8 @@ export type CallsLinkClickMessage = {
link: string | URL;
}
export type CallsJoinRequestMessage = {
callID: string;
}
export type CallsEventHandler = ((viewName: string, msg: any) => void) | ((viewName: string, opts: Electron.SourcesOptions) => Promise<void>);