2021-02-20 17:46:17 +01:00
|
|
|
import {IPCChannel} from "../../../ipc/BrowserIPC";
|
|
|
|
|
|
|
|
export const kPopoutIPCChannelId = "popout-channel";
|
2020-07-20 19:08:13 +02:00
|
|
|
|
|
|
|
export interface PopoutIPCMessage {
|
2021-02-20 17:46:17 +01:00
|
|
|
"hello-popout": { version: string, authenticationCode: string },
|
2021-01-22 16:50:55 +01:00
|
|
|
"hello-controller": { accepted: boolean, message?: string, constructorArguments?: any[] },
|
2020-08-09 18:58:19 +02:00
|
|
|
"invoke-modal-action": {
|
|
|
|
action: "close" | "minimize"
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 16:50:55 +01:00
|
|
|
export type Controller2PopoutMessages = "hello-controller";
|
|
|
|
export type Popout2ControllerMessages = "hello-popout" | "invoke-modal-action";
|
2020-07-20 19:08:13 +02:00
|
|
|
|
2020-08-09 18:58:19 +02:00
|
|
|
export interface SendIPCMessage {
|
2020-07-20 19:08:13 +02:00
|
|
|
"controller": Controller2PopoutMessages;
|
|
|
|
"popout": Popout2ControllerMessages;
|
|
|
|
}
|
2020-08-09 18:58:19 +02:00
|
|
|
|
|
|
|
export interface ReceivedIPCMessage {
|
2020-07-20 19:08:13 +02:00
|
|
|
"controller": Popout2ControllerMessages;
|
|
|
|
"popout": Controller2PopoutMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class EventControllerBase<Type extends "controller" | "popout"> {
|
2021-02-20 17:46:17 +01:00
|
|
|
protected readonly ipcAuthenticationCode: string;
|
|
|
|
protected ipcRemotePeerId: string;
|
2020-07-20 19:08:13 +02:00
|
|
|
protected ipcChannel: IPCChannel;
|
|
|
|
|
2021-02-20 17:46:17 +01:00
|
|
|
protected constructor(ipcAuthenticationCode: string) {
|
|
|
|
this.ipcAuthenticationCode = ipcAuthenticationCode;
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected sendIPCMessage<T extends SendIPCMessage[Type]>(type: T, payload: PopoutIPCMessage[T]) {
|
2021-02-20 17:46:17 +01:00
|
|
|
this.ipcChannel.sendMessage(type, payload, this.ipcRemotePeerId);
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 17:46:17 +01:00
|
|
|
protected handleTypedIPCMessage<T extends ReceivedIPCMessage[Type]>(remoteId: string, isBroadcast: boolean, type: T, payload: PopoutIPCMessage[T]) {
|
|
|
|
|
|
|
|
}
|
2020-08-07 13:40:11 +02:00
|
|
|
|
|
|
|
protected destroyIPC() {
|
|
|
|
this.ipcChannel = undefined;
|
2021-02-20 17:46:17 +01:00
|
|
|
this.ipcRemotePeerId = undefined;
|
2020-08-07 13:40:11 +02:00
|
|
|
}
|
2020-07-20 19:08:13 +02:00
|
|
|
}
|