@callstack/repack-dev-server 5.0.0-next.2 → 5.0.0-rc.1
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.
- package/CHANGELOG.md +17 -3
- package/README.md +1 -1
- package/dist/createServer.d.ts +1 -2
- package/dist/createServer.js +11 -22
- package/dist/createServer.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/api/apiPlugin.js.map +1 -1
- package/dist/plugins/api/index.js.map +1 -1
- package/dist/plugins/compiler/compilerPlugin.js +16 -14
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
- package/dist/plugins/compiler/index.js.map +1 -1
- package/dist/plugins/compiler/types.d.ts +4 -3
- package/dist/plugins/compiler/types.js.map +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.js +5 -29
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
- package/dist/plugins/devtools/index.js.map +1 -1
- package/dist/plugins/favicon/faviconPlugin.js +2 -2
- package/dist/plugins/favicon/faviconPlugin.js.map +1 -1
- package/dist/plugins/favicon/index.js.map +1 -1
- package/dist/plugins/multipart/index.js.map +1 -1
- package/dist/plugins/multipart/multipartPlugin.js +1 -1
- package/dist/plugins/multipart/multipartPlugin.js.map +1 -1
- package/dist/plugins/multipart/types.d.ts +1 -2
- package/dist/plugins/multipart/types.js.map +1 -1
- package/dist/plugins/symbolicate/Symbolicator.d.ts +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +7 -8
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
- package/dist/plugins/symbolicate/index.js.map +1 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -1
- package/dist/plugins/symbolicate/types.d.ts +0 -1
- package/dist/plugins/symbolicate/types.js.map +1 -1
- package/dist/plugins/wss/WebSocketRouter.d.ts +1 -1
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
- package/dist/plugins/wss/WebSocketServer.d.ts +4 -7
- package/dist/plugins/wss/WebSocketServer.js.map +1 -1
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +1 -4
- package/dist/plugins/wss/WebSocketServerAdapter.js +2 -2
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -1
- package/dist/plugins/wss/index.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +4 -5
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +1 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +2 -3
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +7 -7
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -1
- package/dist/plugins/wss/types.d.ts +2 -5
- package/dist/plugins/wss/types.js.map +1 -1
- package/dist/plugins/wss/wssPlugin.d.ts +4 -6
- package/dist/plugins/wss/wssPlugin.js +4 -8
- package/dist/plugins/wss/wssPlugin.js.map +1 -1
- package/dist/types.d.ts +15 -5
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -1
- package/package.json +6 -19
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +0 -64
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +0 -142
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -11,12 +11,8 @@ export declare namespace Server {
|
|
|
11
11
|
interface Config {
|
|
12
12
|
/** Development server options to configure e.g: `port`, `host` etc. */
|
|
13
13
|
options: Options;
|
|
14
|
-
experiments?: Experiments;
|
|
15
14
|
/** Function to create a delegate, which implements crucial functionalities. */
|
|
16
|
-
delegate: (context: DelegateContext) =>
|
|
17
|
-
}
|
|
18
|
-
interface Experiments {
|
|
19
|
-
experimentalDebugger?: boolean;
|
|
15
|
+
delegate: (context: DelegateContext) => Delegate;
|
|
20
16
|
}
|
|
21
17
|
/** Development server options. */
|
|
22
18
|
interface Options {
|
|
@@ -139,6 +135,20 @@ export declare namespace Server {
|
|
|
139
135
|
}
|
|
140
136
|
}
|
|
141
137
|
}
|
|
138
|
+
/** Representation of the compilation progress. */
|
|
139
|
+
export interface ProgressData {
|
|
140
|
+
/** Number of modules built. */
|
|
141
|
+
completed: number;
|
|
142
|
+
/** Total number of modules detect as part of compilation. */
|
|
143
|
+
total: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Type representing a function to send the progress.
|
|
147
|
+
*
|
|
148
|
+
* Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
|
|
149
|
+
* progress to the client who requested the asset.
|
|
150
|
+
*/
|
|
151
|
+
export type SendProgress = (data: ProgressData) => void;
|
|
142
152
|
/**
|
|
143
153
|
* Internal types. Do not use.
|
|
144
154
|
*
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export let Server;
|
|
2
|
+
/** Representation of the compilation progress. */
|
|
3
|
+
/**
|
|
4
|
+
* Type representing a function to send the progress.
|
|
5
|
+
*
|
|
6
|
+
* Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
|
|
7
|
+
* progress to the client who requested the asset.
|
|
8
|
+
*/
|
|
2
9
|
/**
|
|
3
10
|
* Internal types. Do not use.
|
|
4
11
|
*
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n
|
|
1
|
+
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate;\n }\n\n /** Development server options. */\n export interface Options {\n /** Root directory of the project. */\n rootDir: string;\n\n /** Port under which to run the development server. */\n port: number;\n\n /**\n * Hostname or IP address under which to run the development server.\n * When left unspecified, it will listen on all available network interfaces, similarly to listening on '0.0.0.0'.\n */\n host?: string;\n\n /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */\n https?: {\n /** Path to certificate when running server as HTTPS. */\n cert?: string;\n\n /** Path to certificate key when running server as HTTPS. */\n key?: string;\n };\n\n /** Additional endpoints with pre-configured servers */\n endpoints?: Record<string, WebSocketServer>;\n\n /** Whether to enable logging requests. */\n logRequests?: boolean;\n }\n\n /**\n * A complete delegate with implementations for all server functionalities.\n */\n export interface Delegate {\n /** A compiler delegate. */\n compiler: CompilerDelegate;\n\n /** A symbolicator delegate. */\n symbolicator: SymbolicatorDelegate;\n\n /** A logger delegate. */\n logger: LoggerDelegate;\n\n /** An HMR delegate. */\n hmr: HmrDelegate;\n\n /** An messages delegate. */\n messages: MessagesDelegate;\n\n /** An API delegate. */\n api?: Api.Delegate;\n }\n\n /**\n * A delegate context used in `delegate` builder in {@link Config}.\n *\n * Allows to emit logs, notify about compilation events and broadcast events to connected clients.\n */\n export interface DelegateContext {\n /** A logger instance, useful for emitting logs from the delegate. */\n log: FastifyBaseLogger;\n\n /** Send notification about compilation start for given `platform`. */\n notifyBuildStart: (platform: string) => void;\n\n /** Send notification about compilation end for given `platform`. */\n notifyBuildEnd: (platform: string) => void;\n\n /**\n * Broadcast arbitrary event to all connected HMR clients for given `platform`.\n *\n * @param event Arbitrary event to broadcast.\n * @param platform Platform of the clients to which broadcast should be sent.\n * @param clientIds Ids of the client to which broadcast should be sent.\n * If `undefined` the broadcast will be sent to all connected clients for the given `platform`.\n */\n broadcastToHmrClients: <E = any>(\n event: E,\n platform: string,\n clientIds?: string[]\n ) => void;\n\n /**\n * Broadcast arbitrary method-like event to all connected message clients.\n *\n * @param event Arbitrary method-like event to broadcast.\n */\n broadcastToMessageClients: <\n E extends { method: string; params?: Record<string, any> },\n >(\n event: E\n ) => void;\n }\n\n /**\n * Delegate with implementation for logging functions.\n */\n export interface LoggerDelegate {\n /**\n * Callback for when a new log is emitted.\n *\n * @param log An object with log data.\n */\n onMessage: (log: any) => void;\n }\n\n /**\n * Delegate with implementation for messages used in route handlers.\n */\n export interface MessagesDelegate {\n /** Get message to send as a reply for `GET /` route. */\n getHello: () => string;\n\n /** Get message to send as a reply for `GET /status` route. */\n getStatus: () => string;\n }\n\n export namespace Api {\n /** A compilation asset representation for API clients. */\n export interface Asset {\n name: string;\n size: number;\n [key: string]: any;\n }\n\n /** A compilation stats representation for API clients. */\n export interface CompilationStats {\n [key: string]: any;\n }\n\n /**\n * Delegate with implementation for API endpoints.\n */\n export interface Delegate {\n /** Get all platforms - either with already existing compilations or all supported platforms. */\n getPlatforms: () => Promise<string[]>;\n\n /**\n * Get all assets from compilation for given platform.\n * Should return `[]` if the compilation does not exists for given platform.\n */\n getAssets: (platform: string) => Promise<Asset[]>;\n\n /**\n * Get compilation stats for a given platform.\n * Should return `null` if the compilation does not exists for given platform.\n */\n getCompilationStats: (\n platform: string\n ) => Promise<CompilationStats | null>;\n }\n }\n}\n\n/** Representation of the compilation progress. */\nexport interface ProgressData {\n /** Number of modules built. */\n completed: number;\n\n /** Total number of modules detect as part of compilation. */\n total: number;\n}\n\n/**\n * Type representing a function to send the progress.\n *\n * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation\n * progress to the client who requested the asset.\n */\nexport type SendProgress = (data: ProgressData) => void;\n\n/**\n * Internal types. Do not use.\n *\n * @internal\n */\nexport namespace Internal {\n export enum EventTypes {\n BuildStart = 'BuildStart',\n BuildEnd = 'BuildEnd',\n HmrEvent = 'HmrEvent',\n }\n}\n"],"mappings":"WAiBiBA,MAAM;AAoKvB;AASA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAJA,WAKiBC,QAAQ;AAAA,WAAAC,SAAA;EAAA,IACXC,UAAU,0BAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAA,OAAVA,UAAU;EAAA;EAAAD,SAAA,CAAAC,UAAA,GAAAA,UAAA;AAAA,GADPF,QAAQ,KAARA,QAAQ","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@callstack/repack-dev-server",
|
|
3
3
|
"description": "A bundler-agnostic development server for React Native applications as part of @callstack/repack.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "5.0.0-
|
|
5
|
+
"version": "5.0.0-rc.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"@babel/code-frame": "^7.16.7",
|
|
38
38
|
"@fastify/middie": "^8.3.0",
|
|
39
39
|
"@fastify/sensible": "^5.5.0",
|
|
40
|
-
"@react-native/dev-middleware": "^0.
|
|
40
|
+
"@react-native/dev-middleware": "^0.76.1",
|
|
41
41
|
"fastify": "^4.24.3",
|
|
42
42
|
"fastify-favicon": "^4.3.0",
|
|
43
43
|
"fastify-plugin": "^4.5.1",
|
|
44
|
-
"open": "^8.4.0",
|
|
45
44
|
"pretty-format": "^28.1.0",
|
|
46
45
|
"source-map": "^0.7.4",
|
|
47
46
|
"ws": "^8.7.0"
|
|
@@ -49,38 +48,26 @@
|
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@babel/cli": "^7.23.9",
|
|
51
50
|
"@babel/core": "^7.23.9",
|
|
52
|
-
"@react-native-community/cli-
|
|
53
|
-
"@react-native-community/cli-server-api": ">=11.3.1",
|
|
51
|
+
"@react-native-community/cli-server-api": "15.0.1",
|
|
54
52
|
"@types/babel__code-frame": "^7.0.3",
|
|
55
53
|
"@types/node": "18",
|
|
56
54
|
"@types/ws": "^8.5.3",
|
|
57
55
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
58
|
-
"
|
|
59
|
-
"typedoc": "^0.25.3",
|
|
60
|
-
"typedoc-plugin-markdown": "^3.17.1",
|
|
61
|
-
"typescript": "^5.2.2"
|
|
56
|
+
"typescript": "^5.5.3"
|
|
62
57
|
},
|
|
63
58
|
"peerDependencies": {
|
|
64
|
-
"@react-native-community/cli-
|
|
65
|
-
"@react-native-community/cli-server-api": ">=11.3.1"
|
|
59
|
+
"@react-native-community/cli-server-api": ">=13.6.4"
|
|
66
60
|
},
|
|
67
61
|
"peerDependenciesMeta": {
|
|
68
|
-
"@react-native-community/cli-debugger-ui": {
|
|
69
|
-
"optional": true
|
|
70
|
-
},
|
|
71
62
|
"@react-native-community/cli-server-api": {
|
|
72
63
|
"optional": true
|
|
73
64
|
}
|
|
74
65
|
},
|
|
75
66
|
"scripts": {
|
|
76
67
|
"build:js": "babel src --out-dir dist --extensions \".js,.cjs,.ts\" --source-maps --ignore \"**/__tests__/**\" --delete-dir-on-start --copy-files",
|
|
77
|
-
"build:js:watch": "pnpm build:js --watch",
|
|
78
68
|
"build:ts": "tsc --emitDeclarationOnly",
|
|
79
|
-
"build
|
|
80
|
-
"build": "pnpm build:js && pnpm build:ts",
|
|
81
|
-
"docs": "typedoc",
|
|
69
|
+
"build": "pnpm run \"/^build:.*/\"",
|
|
82
70
|
"typecheck": "tsc --noEmit",
|
|
83
|
-
"lint": "eslint --ext \".js,.ts\" src",
|
|
84
71
|
"archive": "pnpm build && pnpm pack"
|
|
85
72
|
}
|
|
86
73
|
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { IncomingMessage } from 'http';
|
|
3
|
-
import type { FastifyInstance } from 'fastify';
|
|
4
|
-
import WebSocket from 'ws';
|
|
5
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
6
|
-
/**
|
|
7
|
-
* Class for creating a WebSocket server and providing a bridge between
|
|
8
|
-
* debugger UI (Remote JS debugger) and the running React Native application.
|
|
9
|
-
*
|
|
10
|
-
* React Native application (aka client) will send and receive messages from the debugger UI
|
|
11
|
-
* which runs inside a browser.
|
|
12
|
-
*
|
|
13
|
-
* @category Development server
|
|
14
|
-
*/
|
|
15
|
-
export declare class WebSocketDebuggerServer extends WebSocketServer {
|
|
16
|
-
/**
|
|
17
|
-
* A WebSocket connection with the debugger UI.
|
|
18
|
-
*/
|
|
19
|
-
private debuggerSocket;
|
|
20
|
-
/**
|
|
21
|
-
* A WebSocket connection with the client (React Native app).
|
|
22
|
-
*/
|
|
23
|
-
private clientSocket;
|
|
24
|
-
/**
|
|
25
|
-
* Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
|
|
26
|
-
* Any logging information, will be passed through standard `fastify.log` API.
|
|
27
|
-
*
|
|
28
|
-
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
29
|
-
*/
|
|
30
|
-
constructor(fastify: FastifyInstance);
|
|
31
|
-
/**
|
|
32
|
-
* Check if debugger UI is connected to the WebSocketDebuggerServer.
|
|
33
|
-
*/
|
|
34
|
-
isDebuggerConnected(): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Send a message to a given WebSocket connection.
|
|
37
|
-
*
|
|
38
|
-
* @param socket WebSocket connection to send the message to.
|
|
39
|
-
* @param message Message to send.
|
|
40
|
-
*/
|
|
41
|
-
send(socket: WebSocket | undefined, message: string): void;
|
|
42
|
-
/**
|
|
43
|
-
* Process new WebSocket connection. The upgrade request should contain `role` query param
|
|
44
|
-
* for determining the type of the connection.
|
|
45
|
-
*
|
|
46
|
-
* @param socket Incoming WebSocket connection.
|
|
47
|
-
* @param request Upgrade request for the connection.
|
|
48
|
-
*/
|
|
49
|
-
onConnection(socket: WebSocket, request: IncomingMessage): void;
|
|
50
|
-
/**
|
|
51
|
-
* Process new WebSocket connection from Debugger UI (Remote JS Debugger).
|
|
52
|
-
* If there's already open connection, the new one gets closed automatically.
|
|
53
|
-
*
|
|
54
|
-
* @param socket Incoming debugger WebSocket connection.
|
|
55
|
-
*/
|
|
56
|
-
onDebuggerConnection(socket: WebSocket): void;
|
|
57
|
-
/**
|
|
58
|
-
* Process new WebSocket connection from React Native app (client)
|
|
59
|
-
* and close any previous connection.
|
|
60
|
-
*
|
|
61
|
-
* @param socket Incoming client WebSocket connection.
|
|
62
|
-
*/
|
|
63
|
-
onClientConnection(socket: WebSocket): void;
|
|
64
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { WebSocketServer } from "../WebSocketServer.js";
|
|
2
|
-
/**
|
|
3
|
-
* Class for creating a WebSocket server and providing a bridge between
|
|
4
|
-
* debugger UI (Remote JS debugger) and the running React Native application.
|
|
5
|
-
*
|
|
6
|
-
* React Native application (aka client) will send and receive messages from the debugger UI
|
|
7
|
-
* which runs inside a browser.
|
|
8
|
-
*
|
|
9
|
-
* @category Development server
|
|
10
|
-
*/
|
|
11
|
-
export class WebSocketDebuggerServer extends WebSocketServer {
|
|
12
|
-
/**
|
|
13
|
-
* A WebSocket connection with the debugger UI.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A WebSocket connection with the client (React Native app).
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
|
|
22
|
-
* Any logging information, will be passed through standard `fastify.log` API.
|
|
23
|
-
*
|
|
24
|
-
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
25
|
-
*/
|
|
26
|
-
constructor(fastify) {
|
|
27
|
-
super(fastify, '/debugger-proxy');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check if debugger UI is connected to the WebSocketDebuggerServer.
|
|
32
|
-
*/
|
|
33
|
-
isDebuggerConnected() {
|
|
34
|
-
return Boolean(this.debuggerSocket);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Send a message to a given WebSocket connection.
|
|
39
|
-
*
|
|
40
|
-
* @param socket WebSocket connection to send the message to.
|
|
41
|
-
* @param message Message to send.
|
|
42
|
-
*/
|
|
43
|
-
send(socket, message) {
|
|
44
|
-
try {
|
|
45
|
-
socket?.send(message);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
this.fastify.log.warn({
|
|
48
|
-
msg: 'Failed to send data to socket',
|
|
49
|
-
error
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Process new WebSocket connection. The upgrade request should contain `role` query param
|
|
56
|
-
* for determining the type of the connection.
|
|
57
|
-
*
|
|
58
|
-
* @param socket Incoming WebSocket connection.
|
|
59
|
-
* @param request Upgrade request for the connection.
|
|
60
|
-
*/
|
|
61
|
-
onConnection(socket, request) {
|
|
62
|
-
const {
|
|
63
|
-
url = ''
|
|
64
|
-
} = request;
|
|
65
|
-
if (url.indexOf('role=debugger') >= 0) {
|
|
66
|
-
this.fastify.log.info({
|
|
67
|
-
msg: 'Chrome Remote JS debugger connected'
|
|
68
|
-
});
|
|
69
|
-
this.onDebuggerConnection(socket);
|
|
70
|
-
} else if (url.indexOf('role=client') >= 0) {
|
|
71
|
-
this.fastify.log.info({
|
|
72
|
-
msg: 'React Native app connected to debugger'
|
|
73
|
-
});
|
|
74
|
-
this.onClientConnection(socket);
|
|
75
|
-
} else {
|
|
76
|
-
socket.close(1011, 'Missing role param');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Process new WebSocket connection from Debugger UI (Remote JS Debugger).
|
|
82
|
-
* If there's already open connection, the new one gets closed automatically.
|
|
83
|
-
*
|
|
84
|
-
* @param socket Incoming debugger WebSocket connection.
|
|
85
|
-
*/
|
|
86
|
-
onDebuggerConnection(socket) {
|
|
87
|
-
if (this.debuggerSocket) {
|
|
88
|
-
socket.close(1011, 'Another debugger is already connected');
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.debuggerSocket = socket;
|
|
92
|
-
const onClose = () => {
|
|
93
|
-
this.fastify.log.info({
|
|
94
|
-
msg: 'Chrome Remote JS debugger disconnected'
|
|
95
|
-
});
|
|
96
|
-
this.debuggerSocket = undefined;
|
|
97
|
-
if (this.clientSocket) {
|
|
98
|
-
this.clientSocket.removeAllListeners();
|
|
99
|
-
this.clientSocket.close(1011, 'Debugger was disconnected');
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
this.debuggerSocket.addEventListener('error', onClose);
|
|
103
|
-
this.debuggerSocket.addEventListener('close', onClose);
|
|
104
|
-
this.debuggerSocket.addEventListener('message', ({
|
|
105
|
-
data
|
|
106
|
-
}) => {
|
|
107
|
-
this.send(this.clientSocket, data.toString());
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Process new WebSocket connection from React Native app (client)
|
|
113
|
-
* and close any previous connection.
|
|
114
|
-
*
|
|
115
|
-
* @param socket Incoming client WebSocket connection.
|
|
116
|
-
*/
|
|
117
|
-
onClientConnection(socket) {
|
|
118
|
-
if (this.clientSocket) {
|
|
119
|
-
this.clientSocket.removeAllListeners();
|
|
120
|
-
this.clientSocket.close(1011, 'Another client is connected');
|
|
121
|
-
this.clientSocket = undefined;
|
|
122
|
-
}
|
|
123
|
-
const onClose = () => {
|
|
124
|
-
this.fastify.log.info({
|
|
125
|
-
msg: 'React Native app disconnected from debugger'
|
|
126
|
-
});
|
|
127
|
-
this.clientSocket = undefined;
|
|
128
|
-
this.send(this.debuggerSocket, JSON.stringify({
|
|
129
|
-
method: '$disconnected'
|
|
130
|
-
}));
|
|
131
|
-
};
|
|
132
|
-
this.clientSocket = socket;
|
|
133
|
-
this.clientSocket.addEventListener('error', onClose);
|
|
134
|
-
this.clientSocket.addEventListener('close', onClose);
|
|
135
|
-
this.clientSocket.addEventListener('message', ({
|
|
136
|
-
data
|
|
137
|
-
}) => {
|
|
138
|
-
this.send(this.debuggerSocket, data.toString());
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=WebSocketDebuggerServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketDebuggerServer.js","names":["WebSocketServer","WebSocketDebuggerServer","constructor","fastify","isDebuggerConnected","Boolean","debuggerSocket","send","socket","message","error","log","warn","msg","onConnection","request","url","indexOf","info","onDebuggerConnection","onClientConnection","close","onClose","undefined","clientSocket","removeAllListeners","addEventListener","data","toString","JSON","stringify","method"],"sources":["../../../../src/plugins/wss/servers/WebSocketDebuggerServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server and providing a bridge between\n * debugger UI (Remote JS debugger) and the running React Native application.\n *\n * React Native application (aka client) will send and receive messages from the debugger UI\n * which runs inside a browser.\n *\n * @category Development server\n */\nexport class WebSocketDebuggerServer extends WebSocketServer {\n /**\n * A WebSocket connection with the debugger UI.\n */\n private debuggerSocket: WebSocket | undefined;\n\n /**\n * A WebSocket connection with the client (React Native app).\n */\n private clientSocket: WebSocket | undefined;\n\n /**\n * Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket server to.\n */\n constructor(fastify: FastifyInstance) {\n super(fastify, '/debugger-proxy');\n }\n\n /**\n * Check if debugger UI is connected to the WebSocketDebuggerServer.\n */\n isDebuggerConnected() {\n return Boolean(this.debuggerSocket);\n }\n\n /**\n * Send a message to a given WebSocket connection.\n *\n * @param socket WebSocket connection to send the message to.\n * @param message Message to send.\n */\n send(socket: WebSocket | undefined, message: string) {\n try {\n socket?.send(message);\n } catch (error) {\n this.fastify.log.warn({ msg: 'Failed to send data to socket', error });\n }\n }\n\n /**\n * Process new WebSocket connection. The upgrade request should contain `role` query param\n * for determining the type of the connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { url = '' } = request;\n if (url.indexOf('role=debugger') >= 0) {\n this.fastify.log.info({ msg: 'Chrome Remote JS debugger connected' });\n this.onDebuggerConnection(socket);\n } else if (url.indexOf('role=client') >= 0) {\n this.fastify.log.info({ msg: 'React Native app connected to debugger' });\n this.onClientConnection(socket);\n } else {\n socket.close(1011, 'Missing role param');\n }\n }\n\n /**\n * Process new WebSocket connection from Debugger UI (Remote JS Debugger).\n * If there's already open connection, the new one gets closed automatically.\n *\n * @param socket Incoming debugger WebSocket connection.\n */\n onDebuggerConnection(socket: WebSocket) {\n if (this.debuggerSocket) {\n socket.close(1011, 'Another debugger is already connected');\n return;\n }\n this.debuggerSocket = socket;\n const onClose = () => {\n this.fastify.log.info({ msg: 'Chrome Remote JS debugger disconnected' });\n this.debuggerSocket = undefined;\n if (this.clientSocket) {\n this.clientSocket.removeAllListeners();\n this.clientSocket.close(1011, 'Debugger was disconnected');\n }\n };\n this.debuggerSocket.addEventListener('error', onClose);\n this.debuggerSocket.addEventListener('close', onClose);\n this.debuggerSocket.addEventListener('message', ({ data }) => {\n this.send(this.clientSocket, data.toString());\n });\n }\n\n /**\n * Process new WebSocket connection from React Native app (client)\n * and close any previous connection.\n *\n * @param socket Incoming client WebSocket connection.\n */\n onClientConnection(socket: WebSocket) {\n if (this.clientSocket) {\n this.clientSocket.removeAllListeners();\n this.clientSocket.close(1011, 'Another client is connected');\n this.clientSocket = undefined;\n }\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'React Native app disconnected from debugger',\n });\n this.clientSocket = undefined;\n this.send(\n this.debuggerSocket,\n JSON.stringify({ method: '$disconnected' })\n );\n };\n\n this.clientSocket = socket;\n this.clientSocket.addEventListener('error', onClose);\n this.clientSocket.addEventListener('close', onClose);\n this.clientSocket.addEventListener('message', ({ data }) => {\n this.send(this.debuggerSocket, data.toString());\n });\n }\n}\n"],"mappings":"SAGSA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,SAASD,eAAe,CAAC;EAC3D;AACF;AACA;;EAGE;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,iBAAiB,CAAC;EACnC;;EAEA;AACF;AACA;EACEC,mBAAmBA,CAAA,EAAG;IACpB,OAAOC,OAAO,CAAC,IAAI,CAACC,cAAc,CAAC;EACrC;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,IAAIA,CAACC,MAA6B,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