import { Event } from "vs/base/common/event"; import { IChannel, IServerChannel } from "vs/base/parts/ipc/common/ipc"; import { createDecorator } from "vs/platform/instantiation/common/instantiation"; import { ReadWriteConnection } from "vs/server/node_modules/@coder/node-browser/out/common/connection"; export const INodeProxyService = createDecorator("nodeProxyService"); export interface INodeProxyService extends ReadWriteConnection { _serviceBrand: any; send(message: string): void; onMessage: Event; onUp: Event; onClose: Event; onDown: Event; } export class NodeProxyChannel implements IServerChannel { constructor(private service: INodeProxyService) {} listen(_: unknown, event: string): Event { switch (event) { case "onMessage": return this.service.onMessage; } throw new Error(`Invalid listen ${event}`); } async call(_: unknown, command: string, args?: any): Promise { switch (command) { case "send": return this.service.send(args[0]); } throw new Error(`Invalid call ${command}`); } } export class NodeProxyChannelClient { _serviceBrand: any; public readonly onMessage: Event; constructor(private readonly channel: IChannel) { this.onMessage = this.channel.listen("onMessage"); } public send(data: string): void { this.channel.call("send", [data]); } }