* Create a DevToolsClient for a given URL object having various query parameters: * * host: * {String} The hostname or IP address to connect to. * port: * {Number} The TCP port to connect to, to use with `host` argument. * remoteId: * {String} Remote client id, for runtimes from the remote-client-manager * ws: * {Boolean} If true, connect via websocket instead of regular TCP connection. * * @param {URL} url * The url to fetch query params from. * @return a promise that resolves a DevToolsClient object */ async function clientFromURL(url) { const params = url.searchParams; // If a remote id was provided we should already have a connected client available. const remoteId = params.get("remoteId"); if (remoteId) { const client = remoteClientManager.getClientByRemoteId(remoteId); if (!client) { throw new Error(`Could not find client with remote id: ${remoteId}`); } return client; } const host = params.get("host"); const port = params.get("port"); const webSocket = !!params.get("ws"); let transport; if (port) { transport = await DevToolsClient.socketConnect({ host, port, webSocket }); } else { // Setup a server if we don't have one already running DevToolsServer.init(); DevToolsServer.registerAllActors(); transport = DevToolsServer.connectPipe(); } return new DevToolsClient(transport); } PK