@react-native/dev-middleware 0.75.0-nightly-20240414-a5eeea814 → 0.75.0-nightly-20240415-e7154bdd9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _Device = _interopRequireDefault(require("./Device"));
|
|
8
8
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
9
|
+
var _timers = require("timers");
|
|
9
10
|
var _url = _interopRequireDefault(require("url"));
|
|
10
11
|
var _ws = _interopRequireDefault(require("ws"));
|
|
11
12
|
function _interopRequireDefault(obj) {
|
|
@@ -22,12 +23,19 @@ function _interopRequireDefault(obj) {
|
|
|
22
23
|
* @oncall react_native
|
|
23
24
|
*/
|
|
24
25
|
|
|
26
|
+
// $FlowFixMe[cannot-resolve-module] libdef missing in RN OSS
|
|
27
|
+
|
|
28
|
+
// Import these from node:timers to get the correct Flow types.
|
|
29
|
+
// $FlowFixMe[cannot-resolve-module] libdef missing in RN OSS
|
|
30
|
+
|
|
25
31
|
const debug = require("debug")("Metro:InspectorProxy");
|
|
26
32
|
const WS_DEVICE_URL = "/inspector/device";
|
|
27
33
|
const WS_DEBUGGER_URL = "/inspector/debug";
|
|
28
34
|
const PAGES_LIST_JSON_URL = "/json";
|
|
29
35
|
const PAGES_LIST_JSON_URL_2 = "/json/list";
|
|
30
36
|
const PAGES_LIST_JSON_VERSION_URL = "/json/version";
|
|
37
|
+
const MAX_PONG_LATENCY_MS = 5000;
|
|
38
|
+
const DEBUGGER_HEARTBEAT_INTERVAL_MS = 10000;
|
|
31
39
|
const INTERNAL_ERROR_CODE = 1011;
|
|
32
40
|
/**
|
|
33
41
|
* Main Inspector Proxy class that connects JavaScript VM inside Android/iOS apps and JS debugger.
|
|
@@ -221,6 +229,7 @@ class InspectorProxy {
|
|
|
221
229
|
if (device == null) {
|
|
222
230
|
throw new Error("Unknown device with ID " + deviceId);
|
|
223
231
|
}
|
|
232
|
+
this.#startHeartbeat(socket, DEBUGGER_HEARTBEAT_INTERVAL_MS);
|
|
224
233
|
device.handleDebuggerConnection(socket, pageId, {
|
|
225
234
|
userAgent: req.headers["user-agent"] ?? query.userAgent ?? null,
|
|
226
235
|
});
|
|
@@ -236,5 +245,43 @@ class InspectorProxy {
|
|
|
236
245
|
});
|
|
237
246
|
return wss;
|
|
238
247
|
}
|
|
248
|
+
|
|
249
|
+
// Starts pinging the socket at the given interval. Compliant clients will
|
|
250
|
+
// respond with pong frame. This serves both to detect when the client
|
|
251
|
+
// has gone away without sending a close frame, and as a keepalive in cases
|
|
252
|
+
// where proxies may drop idle connections (e.g., VS Code tunnels).
|
|
253
|
+
//
|
|
254
|
+
// https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.2
|
|
255
|
+
#startHeartbeat(socket, intervalMs) {
|
|
256
|
+
let terminateTimeout = null;
|
|
257
|
+
const pingTimeout = (0, _timers.setTimeout)(() => {
|
|
258
|
+
if (socket.readyState !== _ws.default.OPEN) {
|
|
259
|
+
// May be connecting or closing, try again later.
|
|
260
|
+
pingTimeout.refresh();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
socket.ping();
|
|
264
|
+
terminateTimeout = (0, _timers.setTimeout)(() => {
|
|
265
|
+
if (socket.readyState !== _ws.default.OPEN) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
// We don't use close() here because that initiates a closing handshake,
|
|
269
|
+
// which will not complete if the other end has gone away - 'close'
|
|
270
|
+
// would not be emitted.
|
|
271
|
+
//
|
|
272
|
+
// terminate() emits 'close' immediately, allowing us to handle it and
|
|
273
|
+
// inform any clients.
|
|
274
|
+
socket.terminate();
|
|
275
|
+
}, MAX_PONG_LATENCY_MS).unref();
|
|
276
|
+
}, intervalMs).unref();
|
|
277
|
+
socket.on("pong", () => {
|
|
278
|
+
terminateTimeout && (0, _timers.clearTimeout)(terminateTimeout);
|
|
279
|
+
pingTimeout.refresh();
|
|
280
|
+
});
|
|
281
|
+
socket.on("close", () => {
|
|
282
|
+
terminateTimeout && (0, _timers.clearTimeout)(terminateTimeout);
|
|
283
|
+
(0, _timers.clearTimeout)(pingTimeout);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
239
286
|
}
|
|
240
287
|
exports.default = InspectorProxy;
|
|
@@ -14,7 +14,6 @@ import type { Experiments } from "../types/Experiments";
|
|
|
14
14
|
import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
|
|
15
15
|
import type { PageDescription } from "./types";
|
|
16
16
|
import type { IncomingMessage, ServerResponse } from "http";
|
|
17
|
-
|
|
18
17
|
import WS from "ws";
|
|
19
18
|
|
|
20
19
|
export interface InspectorProxyQueries {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/dev-middleware",
|
|
3
|
-
"version": "0.75.0-nightly-
|
|
3
|
+
"version": "0.75.0-nightly-20240415-e7154bdd9",
|
|
4
4
|
"description": "Dev server middleware for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@isaacs/ttlcache": "^1.4.1",
|
|
26
|
-
"@react-native/debugger-frontend": "0.75.0-nightly-
|
|
26
|
+
"@react-native/debugger-frontend": "0.75.0-nightly-20240415-e7154bdd9",
|
|
27
27
|
"chrome-launcher": "^0.15.2",
|
|
28
28
|
"chromium-edge-launcher": "^0.2.0",
|
|
29
29
|
"connect": "^3.6.5",
|