MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / CdpClient

Class CdpClient

scripts/e2e-webrtc-reliability.mjs:365–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363}
364
365class CdpClient {
366 constructor(ws) {
367 this.ws = ws;
368 this.nextId = 1;
369 this.pending = new Map();
370 ws.addEventListener("message", (event) => {
371 const message = JSON.parse(event.data);
372 if (message.id && this.pending.has(message.id)) {
373 const { resolve, reject } = this.pending.get(message.id);
374 this.pending.delete(message.id);
375 if (message.error) {
376 reject(new Error(message.error.message));
377 } else {
378 resolve(message.result);
379 }
380 }
381 });
382 }
383
384 close() {
385 this.ws.close();
386 }
387
388 send(method, params = {}) {
389 const id = this.nextId++;
390 this.ws.send(JSON.stringify({ id, method, params }));
391 return new Promise((resolve, reject) => {
392 this.pending.set(id, { resolve, reject });
393 setTimeout(() => {
394 if (this.pending.delete(id)) {
395 reject(new Error(`CDP command timed out: ${method}`));
396 }
397 }, 10_000);
398 });
399 }
400}
401
402async function connectCdp(webSocketDebuggerUrl) {
403 const ws = await createCdpSocket(webSocketDebuggerUrl);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected