metro-inspector-proxy
Advanced tools
Comparing version 0.76.6 to 0.76.7
{ | ||
"name": "metro-inspector-proxy", | ||
"version": "0.76.6", | ||
"version": "0.76.7", | ||
"description": "🚇 Inspector proxy for React Native and dev tools integration.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -141,2 +141,5 @@ "use strict"; | ||
} | ||
getApp() { | ||
return this._app; | ||
} | ||
getPagesList() { | ||
@@ -214,2 +217,31 @@ if (this._lastConnectedReactNativePage) { | ||
/** | ||
* Handles cleaning up a duplicate device connection, by client-side device ID. | ||
* 1. Checks if the same device is attempting to reconnect for the same app. | ||
* 2. If not, close both the device and debugger socket. | ||
* 3. If the debugger connection can be reused, close the device socket only. | ||
* | ||
* This allows users to reload the app, either as result of a crash, or manually | ||
* reloading, without having to restart the debugger. | ||
*/ | ||
handleDuplicateDeviceConnection(newDevice) { | ||
if ( | ||
this._app !== newDevice.getApp() || | ||
this._name !== newDevice.getName() | ||
) { | ||
this._deviceSocket.close(); | ||
this._debuggerConnection?.socket.close(); | ||
} | ||
const oldDebugger = this._debuggerConnection; | ||
this._debuggerConnection = null; | ||
if (oldDebugger) { | ||
oldDebugger.socket.removeAllListeners(); | ||
this._deviceSocket.close(); | ||
newDevice.handleDebuggerConnection( | ||
oldDebugger.socket, | ||
oldDebugger.pageId | ||
); | ||
} | ||
} | ||
// Handles messages received from device: | ||
@@ -216,0 +248,0 @@ // 1. For getPages responses updates local _pages list. |
@@ -135,11 +135,22 @@ /** | ||
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 = this._deviceCounter++; | ||
this._devices.set( | ||
const oldDevice = this._devices.get(deviceId); | ||
const newDevice = new Device( | ||
deviceId, | ||
new Device(deviceId, deviceName, appName, socket, this._projectRoot) | ||
deviceName, | ||
appName, | ||
socket, | ||
this._projectRoot | ||
); | ||
debug(`Got new connection: device=${deviceName}, app=${appName}`); | ||
if (oldDevice) { | ||
oldDevice.handleDuplicateDeviceConnection(newDevice); | ||
} | ||
this._devices.set(deviceId, newDevice); | ||
debug( | ||
`Got new connection: name=${deviceName}, app=${appName}, device=${deviceId}` | ||
); | ||
socket.on("close", () => { | ||
@@ -176,3 +187,3 @@ this._devices.delete(deviceId); | ||
} | ||
const device = this._devices.get(parseInt(deviceId, 10)); | ||
const device = this._devices.get(deviceId); | ||
if (device == null) { | ||
@@ -179,0 +190,0 @@ throw new Error("Unknown device with ID " + deviceId); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65006
890