in packages/metro-inspector-proxy/src/InspectorProxy.js [193:221]
_createDebuggerConnectionWSServer() {
const wss = new WS.Server({
noServer: true,
perMessageDeflate: false,
});
// $FlowFixMe[value-as-type]
wss.on('connection', async (socket: WS, req) => {
try {
const query = url.parse(req.url || '', true).query || {};
const deviceId = query.device;
const pageId = query.page;
if (deviceId == null || pageId == null) {
throw new Error('Incorrect URL - must provide device and page IDs');
}
const device = this._devices.get(parseInt(deviceId, 10));
if (device == null) {
throw new Error('Unknown device with ID ' + deviceId);
}
device.handleDebuggerConnection(socket, pageId);
} catch (e) {
console.error(e);
socket.close(INTERNAL_ERROR_CODE, e);
}
});
return wss;
}