in packages/cross-origin-channel/src/DefaultCrossWindowChannel.ts [32:54]
constructor({ localWindow, remoteWindow, remoteWindowOrigin }: WindowChannelConstructorOptions) {
this.#localWindow = localWindow;
this.#remoteWindow = remoteWindow;
this.#remoteWindowOrigin = remoteWindowOrigin;
this.#messageChannels = new Map<PortName, MessageChannel>();
this.#disposables = [];
this.#disposables.push(
this.addMessageListener<PortChannelRequestMessage>('port-channel-request', event => {
const { name } = event.params;
const channel = this.#messageChannels.get(name);
if (channel) {
this.postMessage({ key: 'port-channel-response', params: { name, port: channel.port2 } });
} else {
this.postMessage({
key: 'port-channel-response-error',
params: { name, error: `Could not find a port with name ${name}` },
});
}
}),
);
}