Skip to content

Commit

Permalink
Allow device identifiers when registering inspectable device
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed May 27, 2023
1 parent c52f355 commit f2ca178
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/metro-inspector-proxy/src/InspectorProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,28 @@ class InspectorProxy {
// $FlowFixMe[value-as-type]
wss.on('connection', async (socket: WS, req) => {
try {
const fallbackDeviceId = String(this._deviceCounter++);

const query = url.parse(req.url || '', true).query || {};
const deviceId = query.device || fallbackDeviceId;
const deviceName = query.name || 'Unknown';
const appName = query.app || 'Unknown';
const deviceId = String(this._deviceCounter++);

const oldDevice = this._devices.get(deviceId);
if (oldDevice) {
// Keep the debugger connection alive when disconnecting the device, if possible
if (oldDevice._name === deviceName && oldDevice._app === appName) {
oldDevice._debuggerConnection = null;
}
oldDevice._deviceSocket.close();
}

this._devices.set(
SdeviceId,
deviceId,
new Device(deviceId, deviceName, appName, socket, this._projectRoot),
);

debug(`Got new connection: device=${deviceName}, app=${appName}`);
debug(`Got new connection: device=${deviceName}, app=${appName}, id=${deviceId}`);

socket.on('close', () => {
this._devices.delete(deviceId);
Expand Down

0 comments on commit f2ca178

Please sign in to comment.