@react-native/dev-middleware
Advanced tools
Comparing version 0.79.0-nightly-20250217-acdddef48 to 0.79.0-nightly-20250218-cda2d11c1
@@ -24,3 +24,3 @@ "use strict"; | ||
const PAGES_LIST_JSON_VERSION_URL = "/json/version"; | ||
const MAX_PONG_LATENCY_MS = 60000; | ||
const DEBUGGER_TIMEOUT_MS = 60000; | ||
const DEBUGGER_HEARTBEAT_INTERVAL_MS = 10000; | ||
@@ -178,3 +178,7 @@ const INTERNAL_ERROR_CODE = 1011; | ||
debug( | ||
`Got new connection: name=${deviceName}, app=${appName}, device=${deviceId}, via=${deviceRelativeBaseUrl.origin}` | ||
"Got new connection: name=%s, app=%s, device=%s, via=%s", | ||
deviceName, | ||
appName, | ||
deviceId, | ||
deviceRelativeBaseUrl.origin | ||
); | ||
@@ -226,3 +230,3 @@ socket.on("close", (code, reason) => { | ||
} | ||
this.#logger?.info("Connection to DevTools established."); | ||
this.#logger?.info("Connection established to DevTools."); | ||
this.#startHeartbeat(socket, DEBUGGER_HEARTBEAT_INTERVAL_MS, appId); | ||
@@ -249,5 +253,4 @@ device.handleDebuggerConnection(socket, pageId, { | ||
#startHeartbeat(socket, intervalMs, appId) { | ||
let shouldSetTerminateTimeout = false; | ||
let terminateTimeout = null; | ||
let latestPingMs = Date.now(); | ||
let terminateTimeout; | ||
const pingTimeout = (0, _timers.setTimeout)(() => { | ||
@@ -258,11 +261,6 @@ if (socket.readyState !== _ws.default.OPEN) { | ||
} | ||
shouldSetTerminateTimeout = true; | ||
latestPingMs = Date.now(); | ||
socket.ping(() => { | ||
if (!shouldSetTerminateTimeout) { | ||
return; | ||
} | ||
shouldSetTerminateTimeout = false; | ||
if (!terminateTimeout) { | ||
terminateTimeout = (0, _timers.setTimeout)(() => { | ||
if (socket.readyState !== _ws.default.OPEN) { | ||
terminateTimeout?.refresh(); | ||
return; | ||
@@ -272,37 +270,35 @@ } | ||
this.#logger?.error( | ||
`Connection terminated with DevTools after not responding for ${ | ||
MAX_PONG_LATENCY_MS / 1000 | ||
} seconds.` | ||
"Connection terminated with DevTools after not responding for %s seconds.", | ||
String(DEBUGGER_TIMEOUT_MS / 1000) | ||
); | ||
this.#eventReporter?.logEvent({ | ||
type: "debugger_timeout", | ||
duration: MAX_PONG_LATENCY_MS, | ||
duration: DEBUGGER_TIMEOUT_MS, | ||
appId, | ||
}); | ||
}, MAX_PONG_LATENCY_MS).unref(); | ||
}); | ||
}, DEBUGGER_TIMEOUT_MS).unref(); | ||
} | ||
latestPingMs = Date.now(); | ||
socket.ping(); | ||
}, intervalMs).unref(); | ||
const onAnyMessageFromDebugger = () => { | ||
shouldSetTerminateTimeout = false; | ||
terminateTimeout && (0, _timers.clearTimeout)(terminateTimeout); | ||
pingTimeout.refresh(); | ||
}; | ||
socket.on("pong", () => { | ||
onAnyMessageFromDebugger(); | ||
const roundtripDuration = Date.now() - latestPingMs; | ||
debug("debugger ping-pong for %s took %dms.", appId, roundtripDuration); | ||
this.#eventReporter?.logEvent({ | ||
type: "debugger_heartbeat", | ||
duration: Date.now() - latestPingMs, | ||
duration: roundtripDuration, | ||
appId, | ||
}); | ||
terminateTimeout?.refresh(); | ||
pingTimeout.refresh(); | ||
}); | ||
socket.on("message", () => { | ||
onAnyMessageFromDebugger(); | ||
terminateTimeout?.refresh(); | ||
}); | ||
socket.on("close", (code, reason) => { | ||
this.#logger?.info( | ||
"Connection to DevTools closed with code '%s' and reason '%s'.", | ||
"Connection closed to DevTools with code '%s' and reason '%s'.", | ||
String(code), | ||
reason | ||
); | ||
shouldSetTerminateTimeout = false; | ||
terminateTimeout && (0, _timers.clearTimeout)(terminateTimeout); | ||
@@ -309,0 +305,0 @@ (0, _timers.clearTimeout)(pingTimeout); |
{ | ||
"name": "@react-native/dev-middleware", | ||
"version": "0.79.0-nightly-20250217-acdddef48", | ||
"version": "0.79.0-nightly-20250218-cda2d11c1", | ||
"description": "Dev server middleware for React Native", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"@isaacs/ttlcache": "^1.4.1", | ||
"@react-native/debugger-frontend": "0.79.0-nightly-20250217-acdddef48", | ||
"@react-native/debugger-frontend": "0.79.0-nightly-20250218-cda2d11c1", | ||
"chrome-launcher": "^0.15.2", | ||
@@ -29,0 +29,0 @@ "chromium-edge-launcher": "^0.2.0", |
106840
2448