80
81
override dispose(): void {
83
>
this._transports.clear();
84
>
for (const transport of transports) {
85
transport.dispose();
86
}
88
>
}
89
90
private _getOrCreateTransport(ctx: TContext): MessagePortProtocolTransport {
92
throw new Error('MessagePortProtocolServer is disposed');
93
}
95
>
let transport = this._transports.get(ctx);
96
>
if (!transport) {
97
>
transport = new MessagePortProtocolTransport();
98
>
this._transports.set(ctx, transport);
99
>
100
>
const onClose = transport.onClose(() => {
101
>
onClose.dispose();
102
>
if (this._transports.get(ctx) === transport) {
103
this._transports.delete(ctx);
104
}
106
>
}
107
>
108
>
return transport;
109
>
}
110
}
111
113
>
114
>
private readonly _onFrame = this._register(new Emitter<string>());
115
>
readonly onFrame = this._onFrame.event;
116
>
117
>
private readonly _onMessage = this._register(new Emitter<ProtocolMessage>());
118
>
readonly onMessage = this._onMessage.event;
119
>
120
>
private readonly _onClose = this._register(new Emitter<void>());
121
>
readonly onClose = this._onClose.event;
122
>
123
>
private _isConnected = false;
124
>
private _isClosed = false;
125
126
get isConnected(): boolean {
128
>
}
129
130
connect(): boolean {
132
return false;
133
}
135
>
this._isConnected = true;
136
>
return true;
137
>
}
138
139
acceptFrame(frame: string): void {
141
>
this._onMessage.fire(JSON.parse(frame) as ProtocolMessage);
142
>
} catch {
143
this.send({ jsonrpc: '2.0', id: null, error: { code: JSON_RPC_PARSE_ERROR, message: 'Parse error' } });
144
}
146
147
send(message: ProtocolMessage | AhpServerNotification | JsonRpcNotification | JsonRpcParseErrorResponse | JsonRpcResponse | JsonRpcRequest): void {