@teardown/cli 1.2.31 → 1.2.34

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.
Files changed (79) hide show
  1. package/package.json +7 -4
  2. package/dist/commands/dev/dev.d.ts +0 -22
  3. package/dist/commands/dev/dev.js +0 -55
  4. package/dist/commands/init/init-teardown.d.ts +0 -9
  5. package/dist/commands/init/init-teardown.js +0 -26
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +0 -20
  8. package/dist/modules/dev/dev-menu/keyboard-handler.d.ts +0 -21
  9. package/dist/modules/dev/dev-menu/keyboard-handler.js +0 -138
  10. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.d.ts +0 -18
  11. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.js +0 -105
  12. package/dist/modules/dev/dev-server/cdp/cdp.adapter.d.ts +0 -6
  13. package/dist/modules/dev/dev-server/cdp/cdp.adapter.js +0 -12
  14. package/dist/modules/dev/dev-server/cdp/index.d.ts +0 -2
  15. package/dist/modules/dev/dev-server/cdp/index.js +0 -18
  16. package/dist/modules/dev/dev-server/cdp/types.d.ts +0 -107
  17. package/dist/modules/dev/dev-server/cdp/types.js +0 -2
  18. package/dist/modules/dev/dev-server/dev-server-checker.d.ts +0 -22
  19. package/dist/modules/dev/dev-server/dev-server-checker.js +0 -72
  20. package/dist/modules/dev/dev-server/dev-server.d.ts +0 -74
  21. package/dist/modules/dev/dev-server/dev-server.js +0 -269
  22. package/dist/modules/dev/dev-server/inspector/device.d.ts +0 -46
  23. package/dist/modules/dev/dev-server/inspector/device.event-reporter.d.ts +0 -37
  24. package/dist/modules/dev/dev-server/inspector/device.event-reporter.js +0 -165
  25. package/dist/modules/dev/dev-server/inspector/device.js +0 -577
  26. package/dist/modules/dev/dev-server/inspector/inspector.d.ts +0 -27
  27. package/dist/modules/dev/dev-server/inspector/inspector.js +0 -204
  28. package/dist/modules/dev/dev-server/inspector/types.d.ts +0 -156
  29. package/dist/modules/dev/dev-server/inspector/types.js +0 -2
  30. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.d.ts +0 -14
  31. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.js +0 -61
  32. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.d.ts +0 -19
  33. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.js +0 -64
  34. package/dist/modules/dev/dev-server/plugins/devtools.plugin.d.ts +0 -10
  35. package/dist/modules/dev/dev-server/plugins/devtools.plugin.js +0 -50
  36. package/dist/modules/dev/dev-server/plugins/favicon.plugin.d.ts +0 -1
  37. package/dist/modules/dev/dev-server/plugins/favicon.plugin.js +0 -19
  38. package/dist/modules/dev/dev-server/plugins/multipart.plugin.d.ts +0 -1
  39. package/dist/modules/dev/dev-server/plugins/multipart.plugin.js +0 -62
  40. package/dist/modules/dev/dev-server/plugins/systrace.plugin.d.ts +0 -1
  41. package/dist/modules/dev/dev-server/plugins/systrace.plugin.js +0 -28
  42. package/dist/modules/dev/dev-server/plugins/types.d.ts +0 -11
  43. package/dist/modules/dev/dev-server/plugins/types.js +0 -2
  44. package/dist/modules/dev/dev-server/plugins/wss/index.d.ts +0 -3
  45. package/dist/modules/dev/dev-server/plugins/wss/index.js +0 -19
  46. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.d.ts +0 -37
  47. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.js +0 -66
  48. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.d.ts +0 -63
  49. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.js +0 -128
  50. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.d.ts +0 -32
  51. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.js +0 -75
  52. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.d.ts +0 -75
  53. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.js +0 -198
  54. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.d.ts +0 -44
  55. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.js +0 -120
  56. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.d.ts +0 -139
  57. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.js +0 -357
  58. package/dist/modules/dev/dev-server/plugins/wss/types.d.ts +0 -6
  59. package/dist/modules/dev/dev-server/plugins/wss/types.js +0 -2
  60. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.d.ts +0 -32
  61. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.js +0 -57
  62. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.d.ts +0 -13
  63. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.js +0 -26
  64. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.d.ts +0 -39
  65. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.js +0 -46
  66. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.d.ts +0 -47
  67. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.js +0 -55
  68. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.d.ts +0 -14
  69. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.js +0 -36
  70. package/dist/modules/dev/dev-server/sybmolicate/types.d.ts +0 -64
  71. package/dist/modules/dev/dev-server/sybmolicate/types.js +0 -2
  72. package/dist/modules/dev/terminal/base.terminal.reporter.d.ts +0 -25
  73. package/dist/modules/dev/terminal/base.terminal.reporter.js +0 -78
  74. package/dist/modules/dev/terminal/terminal.reporter.d.ts +0 -14
  75. package/dist/modules/dev/terminal/terminal.reporter.js +0 -76
  76. package/dist/modules/dev/types.d.ts +0 -20
  77. package/dist/modules/dev/types.js +0 -2
  78. package/dist/modules/dev/utils/log.d.ts +0 -23
  79. package/dist/modules/dev/utils/log.js +0 -73
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.systracePlugin = void 0;
7
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
8
- const node_fs_1 = __importDefault(require("node:fs"));
9
- const cli_tools_1 = require("@react-native-community/cli-tools");
10
- exports.systracePlugin = (0, fastify_plugin_1.default)(async (instance) => {
11
- instance.post("/systrace", async (request, reply) => {
12
- cli_tools_1.logger.info("Dumping profile information...");
13
- const dumpName = `/tmp/dump_${Date.now()}.json`;
14
- // Get the raw body from the request
15
- const rawBody = await request.body;
16
- node_fs_1.default.writeFileSync(dumpName, JSON.stringify(rawBody));
17
- const response =
18
- // biome-ignore lint/style/useTemplate: <explanation>
19
- `Your profile was saved at:\n${dumpName}\n\n` +
20
- 'On Google Chrome navigate to chrome://tracing and then click on "load" ' +
21
- "to load and visualise your profile.\n\n" +
22
- "This message is also printed to your console by the packager so you can copy it :)";
23
- cli_tools_1.logger.info(response);
24
- return reply.send(response);
25
- });
26
- }, {
27
- name: "systrace-plugin",
28
- });
@@ -1,11 +0,0 @@
1
- import type { IncomingHttpHeaders } from 'node:http';
2
- export interface MultipartHandler {
3
- writeChunk: <T>(headers: IncomingHttpHeaders, data: T, isLast?: boolean) => void;
4
- setHeader: (name: string, value: string | string[] | undefined) => void;
5
- end: <T>(data: T) => void;
6
- }
7
- declare module 'fastify' {
8
- interface FastifyReply {
9
- asMultipart: () => MultipartHandler | undefined;
10
- }
11
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export * from "./wss.plugin";
2
- export * from "./web-socket-server";
3
- export * from "./types";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./wss.plugin"), exports);
18
- __exportStar(require("./web-socket-server"), exports);
19
- __exportStar(require("./types"), exports);
@@ -1,37 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import type { TerminalReportableEvent } from "metro/src/lib/TerminalReporter";
3
- import type WebSocket from "ws";
4
- import { WebSocketServer } from "../web-socket-server";
5
- export type WebSocketApiEvent = {
6
- type: "metro_event";
7
- event: TerminalReportableEvent;
8
- };
9
- /**
10
- * Class for creating a WebSocket server for API clients.
11
- * Useful to listening for compilation events and new logs.
12
- *
13
- * @category Development server
14
- */
15
- export declare class WebSocketApiServer extends WebSocketServer {
16
- private clients;
17
- private nextClientId;
18
- /**
19
- * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
20
- * Any logging information, will be passed through standard `fastify.log` API.
21
- *
22
- * @param fastify Fastify instance to attach the WebSocket server to.
23
- */
24
- constructor(fastify: FastifyInstance);
25
- /**
26
- * Send message to all connected API clients.
27
- *
28
- * @param event Event string or object to send.
29
- */
30
- send(event: unknown | WebSocketApiEvent): void;
31
- /**
32
- * Process new WebSocket connection from client application.
33
- *
34
- * @param socket Incoming client's WebSocket connection.
35
- */
36
- onConnection(socket: WebSocket): void;
37
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketApiServer = void 0;
4
- const web_socket_server_1 = require("../web-socket-server");
5
- /**
6
- * Class for creating a WebSocket server for API clients.
7
- * Useful to listening for compilation events and new logs.
8
- *
9
- * @category Development server
10
- */
11
- class WebSocketApiServer extends web_socket_server_1.WebSocketServer {
12
- clients = new Map();
13
- nextClientId = 0;
14
- /**
15
- * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
16
- * Any logging information, will be passed through standard `fastify.log` API.
17
- *
18
- * @param fastify Fastify instance to attach the WebSocket server to.
19
- */
20
- constructor(fastify) {
21
- super(fastify, "/api-console");
22
- }
23
- /**
24
- * Send message to all connected API clients.
25
- *
26
- * @param event Event string or object to send.
27
- */
28
- send(event) {
29
- if (this.clients.size === 0) {
30
- return;
31
- }
32
- const data = typeof event === "string" ? event : JSON.stringify(event);
33
- for (const [, socket] of this.clients.entries()) {
34
- try {
35
- socket.send(data);
36
- }
37
- catch (error) {
38
- this.fastify.log.error("Error sending message to API client", {
39
- error,
40
- });
41
- }
42
- }
43
- }
44
- /**
45
- * Process new WebSocket connection from client application.
46
- *
47
- * @param socket Incoming client's WebSocket connection.
48
- */
49
- onConnection(socket) {
50
- const clientId = `client#${this.nextClientId++}`;
51
- this.clients.set(clientId, socket);
52
- this.fastify.log.info("API client connected", {
53
- clientId,
54
- });
55
- this.clients.set(clientId, socket);
56
- const onClose = () => {
57
- this.fastify.log.info("API client disconnected", {
58
- clientId,
59
- });
60
- this.clients.delete(clientId);
61
- };
62
- socket.addEventListener("error", onClose);
63
- socket.addEventListener("close", onClose);
64
- }
65
- }
66
- exports.WebSocketApiServer = WebSocketApiServer;
@@ -1,63 +0,0 @@
1
- import type { IncomingMessage } from "node:http";
2
- import type { FastifyInstance } from "fastify";
3
- import type WebSocket from "ws";
4
- import { WebSocketServer } from "../web-socket-server";
5
- /**
6
- * Class for creating a WebSocket server and providing a bridge between
7
- * debugger UI (Remote JS debugger) and the running React Native application.
8
- *
9
- * React Native application (aka client) will send and receive messages from the debugger UI
10
- * which runs inside a browser.
11
- *
12
- * @category Development server
13
- */
14
- export declare class WebSocketDebuggerServer extends WebSocketServer {
15
- /**
16
- * A WebSocket connection with the debugger UI.
17
- */
18
- private debuggerSocket;
19
- /**
20
- * A WebSocket connection with the client (React Native app).
21
- */
22
- private clientSocket;
23
- /**
24
- * Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
25
- * Any logging information, will be passed through standard `fastify.log` API.
26
- *
27
- * @param fastify Fastify instance to attach the WebSocket server to.
28
- */
29
- constructor(fastify: FastifyInstance);
30
- /**
31
- * Check if debugger UI is connected to the WebSocketDebuggerServer.
32
- */
33
- isDebuggerConnected(): boolean;
34
- /**
35
- * Send a message to a given WebSocket connection.
36
- *
37
- * @param socket WebSocket connection to send the message to.
38
- * @param message Message to send.
39
- */
40
- send(socket: WebSocket | undefined, message: string): void;
41
- /**
42
- * Process new WebSocket connection. The upgrade request should contain `role` query param
43
- * for determining the type of the connection.
44
- *
45
- * @param socket Incoming WebSocket connection.
46
- * @param request Upgrade request for the connection.
47
- */
48
- onConnection(socket: WebSocket, request: IncomingMessage): void;
49
- /**
50
- * Process new WebSocket connection from Debugger UI (Remote JS Debugger).
51
- * If there's already open connection, the new one gets closed automatically.
52
- *
53
- * @param socket Incoming debugger WebSocket connection.
54
- */
55
- onDebuggerConnection(socket: WebSocket): void;
56
- /**
57
- * Process new WebSocket connection from React Native app (client)
58
- * and close any previous connection.
59
- *
60
- * @param socket Incoming client WebSocket connection.
61
- */
62
- onClientConnection(socket: WebSocket): void;
63
- }
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketDebuggerServer = void 0;
4
- const web_socket_server_1 = require("../web-socket-server");
5
- /**
6
- * Class for creating a WebSocket server and providing a bridge between
7
- * debugger UI (Remote JS debugger) and the running React Native application.
8
- *
9
- * React Native application (aka client) will send and receive messages from the debugger UI
10
- * which runs inside a browser.
11
- *
12
- * @category Development server
13
- */
14
- class WebSocketDebuggerServer extends web_socket_server_1.WebSocketServer {
15
- /**
16
- * A WebSocket connection with the debugger UI.
17
- */
18
- debuggerSocket;
19
- /**
20
- * A WebSocket connection with the client (React Native app).
21
- */
22
- clientSocket;
23
- /**
24
- * Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
25
- * Any logging information, will be passed through standard `fastify.log` API.
26
- *
27
- * @param fastify Fastify instance to attach the WebSocket server to.
28
- */
29
- constructor(fastify) {
30
- super(fastify, "/debugger-proxy");
31
- }
32
- /**
33
- * Check if debugger UI is connected to the WebSocketDebuggerServer.
34
- */
35
- isDebuggerConnected() {
36
- return Boolean(this.debuggerSocket);
37
- }
38
- /**
39
- * Send a message to a given WebSocket connection.
40
- *
41
- * @param socket WebSocket connection to send the message to.
42
- * @param message Message to send.
43
- */
44
- send(socket, message) {
45
- try {
46
- socket?.send(message);
47
- }
48
- catch (error) {
49
- this.fastify.log.warn({ msg: "Failed to send data to socket", error });
50
- }
51
- }
52
- /**
53
- * Process new WebSocket connection. The upgrade request should contain `role` query param
54
- * for determining the type of the connection.
55
- *
56
- * @param socket Incoming WebSocket connection.
57
- * @param request Upgrade request for the connection.
58
- */
59
- onConnection(socket, request) {
60
- console.log("WebSocketDebuggerServer onConnection");
61
- const { url = "" } = request;
62
- if (url.indexOf("role=debugger") >= 0) {
63
- this.fastify.log.info({ msg: "Remote debugger connected" });
64
- this.onDebuggerConnection(socket);
65
- }
66
- else if (url.indexOf("role=client") >= 0) {
67
- this.fastify.log.info({ msg: "React Native app connected to debugger" });
68
- this.onClientConnection(socket);
69
- }
70
- else {
71
- socket.close(1011, "Missing role param");
72
- }
73
- }
74
- /**
75
- * Process new WebSocket connection from Debugger UI (Remote JS Debugger).
76
- * If there's already open connection, the new one gets closed automatically.
77
- *
78
- * @param socket Incoming debugger WebSocket connection.
79
- */
80
- onDebuggerConnection(socket) {
81
- if (this.debuggerSocket) {
82
- socket.close(1011, "Another debugger is already connected");
83
- return;
84
- }
85
- this.debuggerSocket = socket;
86
- const onClose = () => {
87
- this.fastify.log.info({ msg: "Remote debugger disconnected" });
88
- this.debuggerSocket = undefined;
89
- if (this.clientSocket) {
90
- this.clientSocket.removeAllListeners();
91
- this.clientSocket.close(1011, "Debugger was disconnected");
92
- }
93
- };
94
- this.debuggerSocket.addEventListener("error", onClose);
95
- this.debuggerSocket.addEventListener("close", onClose);
96
- this.debuggerSocket.addEventListener("message", ({ data }) => {
97
- this.send(this.clientSocket, data.toString());
98
- });
99
- }
100
- /**
101
- * Process new WebSocket connection from React Native app (client)
102
- * and close any previous connection.
103
- *
104
- * @param socket Incoming client WebSocket connection.
105
- */
106
- onClientConnection(socket) {
107
- console.log("WebSocketDebuggerServer onClientConnection");
108
- if (this.clientSocket) {
109
- this.clientSocket.removeAllListeners();
110
- this.clientSocket.close(1011, "Another client is connected");
111
- this.clientSocket = undefined;
112
- }
113
- const onClose = () => {
114
- this.fastify.log.info({
115
- msg: "React Native app disconnected from debugger",
116
- });
117
- this.clientSocket = undefined;
118
- this.send(this.debuggerSocket, JSON.stringify({ method: "$disconnected" }));
119
- };
120
- this.clientSocket = socket;
121
- this.clientSocket.addEventListener("error", onClose);
122
- this.clientSocket.addEventListener("close", onClose);
123
- this.clientSocket.addEventListener("message", ({ data }) => {
124
- this.send(this.debuggerSocket, data.toString());
125
- });
126
- }
127
- }
128
- exports.WebSocketDebuggerServer = WebSocketDebuggerServer;
@@ -1,32 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import type WebSocket from "ws";
3
- import { WebSocketServer } from "../web-socket-server";
4
- /**
5
- * Class for creating a WebSocket server for communication with React Native clients.
6
- * All client logs - logs from React Native application - are processed here.
7
- *
8
- * @category Development server
9
- */
10
- export declare class WebSocketDevClientServer extends WebSocketServer {
11
- private clients;
12
- private nextClientId;
13
- /**
14
- * Create new instance of WebSocketDevClientServer and attach it to the given Fastify instance.
15
- * Any logging information, will be passed through standard `fastify.log` API.
16
- *
17
- * @param fastify Fastify instance to attach the WebSocket server to.
18
- */
19
- constructor(fastify: FastifyInstance);
20
- /**
21
- * Process client message.
22
- *
23
- * @param message Stringified client message.
24
- */
25
- processMessage(message: string): void;
26
- /**
27
- * Process new WebSocket connection from client application.
28
- *
29
- * @param socket Incoming client's WebSocket connection.
30
- */
31
- onConnection(socket: WebSocket): void;
32
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketDevClientServer = void 0;
4
- const web_socket_server_1 = require("../web-socket-server");
5
- /**
6
- * Class for creating a WebSocket server for communication with React Native clients.
7
- * All client logs - logs from React Native application - are processed here.
8
- *
9
- * @category Development server
10
- */
11
- class WebSocketDevClientServer extends web_socket_server_1.WebSocketServer {
12
- clients = new Map();
13
- nextClientId = 0;
14
- /**
15
- * Create new instance of WebSocketDevClientServer and attach it to the given Fastify instance.
16
- * Any logging information, will be passed through standard `fastify.log` API.
17
- *
18
- * @param fastify Fastify instance to attach the WebSocket server to.
19
- */
20
- constructor(fastify) {
21
- super(fastify, "/__client");
22
- }
23
- /**
24
- * Process client message.
25
- *
26
- * @param message Stringified client message.
27
- */
28
- processMessage(message) {
29
- console.log("WebSocketDevClientServer processMessage", message);
30
- const { type, ...body } = JSON.parse(message);
31
- switch (type) {
32
- case "client-log":
33
- if (body.level === "error") {
34
- this.fastify.log.error({ issuer: "Console", msg: body.data });
35
- }
36
- else if (body.level === "warn") {
37
- this.fastify.log.warn({ issuer: "Console", msg: body.data });
38
- }
39
- else if (body.level === "info" || body.level === "log") {
40
- this.fastify.log.info({ issuer: "Console", msg: body.data });
41
- }
42
- else {
43
- // body.level === 'debug' || body.level === 'trace'
44
- this.fastify.log.debug({ issuer: "Console", msg: body.data });
45
- }
46
- break;
47
- default:
48
- this.fastify.log.warn({ msg: "Unknown client message", message });
49
- }
50
- }
51
- /**
52
- * Process new WebSocket connection from client application.
53
- *
54
- * @param socket Incoming client's WebSocket connection.
55
- */
56
- onConnection(socket) {
57
- const clientId = `client#${this.nextClientId++}`;
58
- console.log("WebSocketDevClientServer onConnection", clientId);
59
- this.clients.set(clientId, socket);
60
- this.fastify.log.debug({ msg: "React Native client connected", clientId });
61
- const onClose = () => {
62
- this.fastify.log.debug({
63
- msg: "React Native client disconnected",
64
- clientId,
65
- });
66
- this.clients.delete(clientId);
67
- };
68
- socket.addEventListener("error", onClose);
69
- socket.addEventListener("close", onClose);
70
- socket.addEventListener("message", (event) => {
71
- this.processMessage(event.data.toString());
72
- });
73
- }
74
- }
75
- exports.WebSocketDevClientServer = WebSocketDevClientServer;
@@ -1,75 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import type WebSocket from "ws";
3
- import { WebSocketServer } from "../web-socket-server";
4
- import type { WebSocketMessageServer } from "./web-socket-message.server";
5
- /**
6
- * {@link WebSocketEventsServer} configuration options.
7
- */
8
- export interface WebSocketEventsServerConfig {
9
- /** Instance of a {@link WebSocketMessageServer} which can be used for broadcasting. */
10
- webSocketMessageServer: WebSocketMessageServer;
11
- }
12
- /**
13
- * Represents a command that connected clients can send to the {@link WebSocketEventsServer}.
14
- */
15
- export interface Command {
16
- version: number;
17
- type: "command";
18
- command: string;
19
- params?: any;
20
- }
21
- /**
22
- * Represents an event message.
23
- */
24
- export interface EventMessage {
25
- error?: Error | string;
26
- type?: string;
27
- data?: any;
28
- }
29
- /**
30
- * Class for creating a WebSocket server to process events and reports.
31
- *
32
- * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/eventsSocketServer.ts
33
- *
34
- * @category Development server
35
- */
36
- export declare class WebSocketEventsServer extends WebSocketServer {
37
- private config;
38
- static readonly PROTOCOL_VERSION = 2;
39
- private clients;
40
- private nextClientId;
41
- /**
42
- * Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
43
- * Any logging information, will be passed through standard `fastify.log` API.
44
- *
45
- * @param fastify Fastify instance to attach the WebSocket server to.
46
- * @param config Configuration object.
47
- */
48
- constructor(fastify: FastifyInstance, config: WebSocketEventsServerConfig);
49
- /**
50
- * Parse received command message from connected client.
51
- *
52
- * @param data Stringified command message to parse.
53
- * @returns Parsed command or `undefined` if parsing failed.
54
- */
55
- parseMessage(data: string): Command | undefined;
56
- /**
57
- * Stringify `message` into a format that can be transported as a `string`.
58
- *
59
- * @param message Message to serialize.
60
- * @returns String representation of a `message` or `undefined` if serialization failed.
61
- */
62
- serializeMessage(message: EventMessage, clientId?: string): string | undefined;
63
- /**
64
- * Broadcast event to all connected clients.
65
- *
66
- * @param event Event message to broadcast.
67
- */
68
- broadcastEvent(event: EventMessage): void;
69
- /**
70
- * Process new client's WebSocket connection.
71
- *
72
- * @param socket Incoming WebSocket connection.
73
- */
74
- onConnection(socket: WebSocket): void;
75
- }