MCPcopy
hub / github.com/microsoft/vscode-js-debug / createServer

Method createServer

src/adapter/cdpProxy.ts:235–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233 }
234
235 private async createServer() {
236 const path = `/${randomBytes(20).toString('hex')}`;
237 const server = await acquireTrackedWebSocketServer(this.portTracker, {
238 perMessageDeflate: true,
239 path,
240 });
241
242 this.logger.info(LogTag.ProxyActivity, 'activated cdp proxy');
243
244 server.on('connection', client => {
245 const clientHandle = new ClientHandle(client, this.logger);
246 this.logger.info(LogTag.ProxyActivity, 'accepted proxy connection', {
247 id: clientHandle.id,
248 });
249
250 client.on('close', () => {
251 this.logger.verbose(LogTag.ProxyActivity, 'closed proxy connection', {
252 id: clientHandle.id,
253 });
254 this.disposables.disposeObject(clientHandle);
255 });
256
257 client.on('message', async d => {
258 let message: CdpProtocol.ICommand;
259 try {
260 message = JSON.parse(d.toString());
261 } catch (e) {
262 return clientHandle.send({
263 id: 0,
264 error: { code: ProxyErrors.ParseError, message: e.message },
265 });
266 }
267
268 this.logger.verbose(LogTag.ProxyActivity, 'received proxy message', message);
269
270 const { method, params, id = 0 } = message;
271 const [domain, fn] = method.split('.');
272 try {
273 const result = domain === jsDebugDomain
274 ? await this.invokeJsDebugDomainMethod(clientHandle, fn, params)
275 : await this.invokeCdpMethod(clientHandle, domain, fn, params);
276 clientHandle.send({ id, result });
277 } catch (e) {
278 const error = e instanceof ProtocolError && e.cause
279 ? e.cause
280 : { code: 0, message: e.message };
281 clientHandle.send({ id, error });
282 }
283 });
284 });
285
286 return { server, path };
287 }
288
289 /**
290 * @inheritdoc

Callers 10

proxyMethod · 0.95
innerCreateServerMethod · 0.80
startDebugServerFunction · 0.80
vsDebugServer.tsFile · 0.80
startDebugServerFunction · 0.80
_startServerFunction · 0.80
acquirePortNumberFunction · 0.80
makeAcquireTcpServerFunction · 0.80
acquireTrackedServerFunction · 0.80

Calls 10

sendMethod · 0.95
invokeCdpMethodMethod · 0.95
disposeObjectMethod · 0.80
infoMethod · 0.65
onMethod · 0.65
verboseMethod · 0.65
parseMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected