229
230
constructor(
232
>
private readonly _endpoint: IAgentHostUpstreamEndpoint,
233
>
private readonly _logService: ILogService,
234
>
upstreamFactory?: UpstreamConnectionFactory,
235
>
) {
236
>
super();
237
>
this._upstreamFactory = upstreamFactory ?? defaultUpstreamFactory(_logService);
238
>
this._register(ipcServer.onDidRemoveConnection(c => this._disposeCtx(c.ctx as unknown as TContext)));
239
>
}
240
241
listen<T>(ctx: TContext, event: string): Event<T> {
243
>
switch (event) {
244
>
case 'frame': return conn.onFrame as Event<unknown> as Event<T>;
245
>
case 'close': return conn.onClose as Event<unknown> as Event<T>;
246
>
}
247
throw new Error(`Invalid listen: ${event}`);
249
250
async call<T>(ctx: TContext, command: string, arg?: unknown): Promise<T> {
252
>
switch (command) {
253
>
case 'connect':
254
>
this._logService.info(`[AgentHostChannel] Renderer ctx=${String(ctx)} requested connect to upstream`);
255
>
await conn.connect();
256
>
return undefined as T;
257
>
case 'send':
258
if (typeof arg !== 'string') {
259
throw new Error('send: arg must be a string frame');