@callstack/repack-dev-server 5.0.0-rc.0 → 5.0.0-rc.10
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/dist/createServer.d.ts +3 -2
- package/dist/createServer.js +110 -134
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/plugins/api/apiPlugin.d.ts +1 -1
- package/dist/plugins/api/apiPlugin.js +21 -28
- package/dist/plugins/api/index.d.ts +1 -1
- package/dist/plugins/api/index.js +1 -2
- package/dist/plugins/compiler/compilerPlugin.d.ts +1 -1
- package/dist/plugins/compiler/compilerPlugin.js +53 -62
- package/dist/plugins/compiler/index.d.ts +2 -2
- package/dist/plugins/compiler/index.js +2 -3
- package/dist/plugins/compiler/types.d.ts +1 -1
- package/dist/plugins/compiler/types.js +0 -1
- package/dist/plugins/devtools/devtoolsPlugin.d.ts +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.js +16 -43
- package/dist/plugins/devtools/index.d.ts +1 -1
- package/dist/plugins/devtools/index.js +1 -2
- package/dist/plugins/favicon/faviconPlugin.js +3 -7
- package/dist/plugins/favicon/index.d.ts +1 -1
- package/dist/plugins/favicon/index.js +1 -2
- package/dist/plugins/multipart/index.d.ts +2 -2
- package/dist/plugins/multipart/index.js +2 -3
- package/dist/plugins/multipart/multipartPlugin.js +44 -42
- package/dist/plugins/multipart/types.js +0 -1
- package/dist/plugins/symbolicate/Symbolicator.d.ts +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +172 -190
- package/dist/plugins/symbolicate/index.d.ts +3 -3
- package/dist/plugins/symbolicate/index.js +3 -4
- package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +1 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +29 -40
- package/dist/plugins/symbolicate/types.js +0 -1
- package/dist/plugins/wss/WebSocketRouter.d.ts +1 -1
- package/dist/plugins/wss/WebSocketRouter.js +39 -44
- package/dist/plugins/wss/WebSocketServer.d.ts +1 -1
- package/dist/plugins/wss/WebSocketServer.js +23 -38
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +1 -1
- package/dist/plugins/wss/WebSocketServerAdapter.js +16 -19
- package/dist/plugins/wss/index.d.ts +3 -3
- package/dist/plugins/wss/index.js +3 -4
- package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js +47 -53
- package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +58 -80
- package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketEventsServer.js +146 -164
- package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +72 -79
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +309 -326
- package/dist/plugins/wss/types.js +0 -1
- package/dist/plugins/wss/wssPlugin.d.ts +8 -10
- package/dist/plugins/wss/wssPlugin.js +37 -46
- package/dist/types.d.ts +6 -10
- package/dist/types.js +8 -18
- package/package.json +7 -17
- package/CHANGELOG.md +0 -156
- package/dist/createServer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugins/api/apiPlugin.js.map +0 -1
- package/dist/plugins/api/index.js.map +0 -1
- package/dist/plugins/compiler/compilerPlugin.js.map +0 -1
- package/dist/plugins/compiler/index.js.map +0 -1
- package/dist/plugins/compiler/types.js.map +0 -1
- package/dist/plugins/devtools/devtoolsPlugin.js.map +0 -1
- package/dist/plugins/devtools/index.js.map +0 -1
- package/dist/plugins/favicon/faviconPlugin.js.map +0 -1
- package/dist/plugins/favicon/index.js.map +0 -1
- package/dist/plugins/multipart/index.js.map +0 -1
- package/dist/plugins/multipart/multipartPlugin.js.map +0 -1
- package/dist/plugins/multipart/types.js.map +0 -1
- package/dist/plugins/symbolicate/Symbolicator.js.map +0 -1
- package/dist/plugins/symbolicate/index.js.map +0 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +0 -1
- package/dist/plugins/symbolicate/types.js.map +0 -1
- package/dist/plugins/wss/WebSocketRouter.js.map +0 -1
- package/dist/plugins/wss/WebSocketServer.js.map +0 -1
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +0 -1
- package/dist/plugins/wss/index.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +0 -63
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +0 -142
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +0 -1
- package/dist/plugins/wss/types.js.map +0 -1
- package/dist/plugins/wss/wssPlugin.js.map +0 -1
- package/dist/types.js.map +0 -1
- /package/{dist/img → static}/favicon.ico +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketServerAdapter.js","names":["WebSocketServerAdapter","constructor","fastify","path","server","shouldUpgrade","pathname","log","warn","msg","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServerAdapter.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { FastifyInstance } from 'fastify';\nimport type { WebSocketServer } from 'ws';\nimport type { WebSocketServerInterface } from './types';\n\nexport class WebSocketServerAdapter implements WebSocketServerInterface {\n constructor(\n private fastify: FastifyInstance,\n private path: string,\n private server?: WebSocketServer\n ) {}\n\n shouldUpgrade(pathname: string) {\n if (!this.server) {\n this.fastify.log.warn({ msg: `No handler active for ${this.path}` });\n return false;\n }\n return this.path === pathname;\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server?.handleUpgrade(request, socket, head, (webSocket) => {\n this.server?.emit('connection', webSocket, request);\n });\n }\n}\n"],"mappings":"AAMA,OAAO,MAAMA,sBAAsB,CAAqC;EACtEC,WAAWA,CACDC,OAAwB,EACxBC,IAAY,EACZC,MAAwB,EAChC;IAAA,KAHQF,OAAwB,GAAxBA,OAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;IAAA,KACZC,MAAwB,GAAxBA,MAAwB;EAC/B;EAEHC,aAAaA,CAACC,QAAgB,EAAE;IAC9B,IAAI,CAAC,IAAI,CAACF,MAAM,EAAE;MAChB,IAAI,CAACF,OAAO,CAACK,GAAG,CAACC,IAAI,CAAC;QAAEC,GAAG,EAAE,yBAAyB,IAAI,CAACN,IAAI;MAAG,CAAC,CAAC;MACpE,OAAO,KAAK;IACd;IACA,OAAO,IAAI,CAACA,IAAI,KAAKG,QAAQ;EAC/B;EAEAI,OAAOA,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,EAAE;IAC9D,IAAI,CAACT,MAAM,EAAEU,aAAa,CAACH,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAGE,SAAS,IAAK;MAC/D,IAAI,CAACX,MAAM,EAAEY,IAAI,CAAC,YAAY,EAAED,SAAS,EAAEJ,OAAO,CAAC;IACrD,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/wss/index.ts"],"sourcesContent":["export { default } from './wssPlugin';\nexport * from './WebSocketServer';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketApiServer.js","names":["WebSocketServer","WebSocketApiServer","clients","Map","nextClientId","constructor","fastify","send","event","data","JSON","stringify","socket","entries","onConnection","clientId","set","log","debug","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for API clients.\n * Useful to listening for compilation events and new logs.\n *\n * @category Development server\n */\nexport class WebSocketApiServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketApiServer 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, '/api');\n }\n\n /**\n * Send message to all connected API clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data);\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.debug({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'API client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,MAAM,CAAC;EACxB;;EAEA;AACF;AACA;AACA;AACA;EACEC,IAAIA,CAACC,KAAU,EAAE;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGE,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;IAEtE,KAAK,MAAM,GAAGI,MAAM,CAAC,IAAI,IAAI,CAACV,OAAO,CAACW,OAAO,CAAC,CAAC,EAAE;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAI,CAACE,IAAI,CAAC;MACnB,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;;EAEA;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACF,MAAiB,EAAE;IAC9B,MAAMG,QAAQ,GAAG,UAAU,IAAI,CAACX,YAAY,EAAE,EAAE;IAChD,IAAI,CAACF,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,IAAI,CAACN,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;MAAEC,GAAG,EAAE,sBAAsB;MAAEJ;IAAS,CAAC,CAAC;IACjE,IAAI,CAACb,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,MAAMQ,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACd,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;QACrBC,GAAG,EAAE,yBAAyB;QAC9BJ;MACF,CAAC,CAAC;MACF,IAAI,CAACb,OAAO,CAACmB,MAAM,CAACN,QAAQ,CAAC;IAC/B,CAAC;IAEDH,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCR,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;EAC3C;AACF","ignoreList":[]}
|
|
@@ -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 '../WebSocketServer';
|
|
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,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 'node:http';\nimport type { FastifyInstance } from 'fastify';\nimport type 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,EAAEC,OAAe,EAAE;IACnD,IAAI;MACFD,MAAM,EAAED,IAAI,CAACE,OAAO,CAAC;IACvB,CAAC,CAAC,OAAOC,KAAK,EAAE;MACd,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACC,IAAI,CAAC;QAAEC,GAAG,EAAE,+BAA+B;QAAEH;MAAM,CAAC,CAAC;IACxE;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEI,YAAYA,CAACN,MAAiB,EAAEO,OAAwB,EAAE;IACxD,MAAM;MAAEC,GAAG,GAAG;IAAG,CAAC,GAAGD,OAAO;IAC5B,IAAIC,GAAG,CAACC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;MACrC,IAAI,CAACd,OAAO,CAACQ,GAAG,CAACO,IAAI,CAAC;QAAEL,GAAG,EAAE;MAAsC,CAAC,CAAC;MACrE,IAAI,CAACM,oBAAoB,CAACX,MAAM,CAAC;IACnC,CAAC,MAAM,IAAIQ,GAAG,CAACC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;MAC1C,IAAI,CAACd,OAAO,CAACQ,GAAG,CAACO,IAAI,CAAC;QA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C;MACtC,IAAI,CAACD,YAAY,CAACH,KAAK,CAAC,IAAI,EAAE,6BAA6B,CAAC;MAC5D,IAAI,CAACG,YAAY,GAAGD,SAAS;IAC/B;IAEA,MAAMD,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACnB,OAAO,CAACQ,GAAG,CAACO,IAAI,CAAC;QACpBL,GAAG,EAAE;MACP,CAAC,CAAC;MACF,IAAI,CAACW,YAAY,GAAGD,SAAS;MAC7B,IAAI,CAAChB,IAAI,CACP,IAAI,CAACD,cAAc,EACnBuB,IAAI,CAACC,SAAS,CAAC;QAAEC,MAAM,EAAE;MAAgB,CAAC,CAC5C,CAAC;IACH,CAAC;IAED,IAAI,CAACP,YAAY,GAAGhB,MAAM;IAC1B,IAAI,CAACgB,YAAY,CAACE,gBAAgB,CAAC,OAAO,EAAEJ,OAAO,CAAC;IACpD,IAAI,CAACE,YAAY,CAACE,gBAAgB,CAAC,OAAO,EAAEJ,OAAO,CAAC;IACpD,IAAI,CAACE,YAAY,CAACE,gBAAgB,CAAC,SAAS,EAAE,CAAC;MAAEC;IAAK,CAAC,KAAK;MAC1D,IAAI,CAACpB,IAAI,CAAC,IAAI,CAACD,cAAc,EAAEqB,IAAI,CAACC,QAAQ,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketDevClientServer.js","names":["WebSocketServer","WebSocketDevClientServer","clients","Map","nextClientId","constructor","fastify","processMessage","message","type","body","JSON","parse","level","log","error","issuer","msg","data","warn","info","debug","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for communication with React Native clients.\n * All client logs - logs from React Native application - are processed here.\n *\n * @category Development server\n */\nexport class WebSocketDevClientServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDevClientServer 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, '/__client');\n }\n\n /**\n * Process client message.\n *\n * @param message Stringified client message.\n */\n processMessage(message: string) {\n const { type, ...body } = JSON.parse(message);\n switch (type) {\n case 'client-log':\n if (body.level === 'error') {\n this.fastify.log.error({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'warn') {\n this.fastify.log.warn({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'info' || body.level === 'log') {\n this.fastify.log.info({ issuer: 'Console', msg: body.data });\n } else {\n // body.level === 'debug' || body.level === 'trace'\n this.fastify.log.debug({ issuer: 'Console', msg: body.data });\n }\n break;\n default:\n this.fastify.log.warn({ msg: 'Unknown client message', message });\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n this.fastify.log.debug({ msg: 'React Native client connected', clientId });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'React Native client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n this.processMessage(event.data.toString());\n });\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,SAASD,eAAe,CAAC;EACpDE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,WAAW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IAChD,IAAI,CAACF,OAAO,CAACuB,GAAG,CAACD,QAAQ,EAAED,MAAM,CAAC;IAClC,IAAI,CAACjB,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;MAAEJ,GAAG,EAAE,+BAA+B;MAAEO;IAAS,CAAC,CAAC;IAE1E,MAAME,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACpB,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;QACrBJ,GAAG,EAAE,kCAAkC;QACvCO;MACF,CAAC,CAAC;MACF,IAAI,CAACtB,OAAO,CAACyB,MAAM,CAACH,QAAQ,CAAC;IAC/B,CAAC;IAEDD,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,SAAS,EAAGC,KAAK,IAAK;MAC5C,IAAI,CAACtB,cAAc,CAACsB,KAAK,CAACX,IAAI,CAACY,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketEventsServer.js","names":["prettyFormat","WebSocketServer","WebSocketEventsServer","PROTOCOL_VERSION","clients","Map","nextClientId","constructor","fastify","config","verifyClient","origin","test","parseMessage","data","message","JSON","parse","version","log","error","msg","undefined","serializeMessage","toSerialize","Error","default","escapeString","highlight","maxDepth","min","type","map","item","plugins","ReactElement","stringify","broadcastEvent","event","size","serialized","clientId","socket","entries","send","_skipBroadcast","onConnection","set","debug","onClose","removeAllListeners","delete","addEventListener","toString","webSocketMessageServer","broadcast","command","params"],"sources":["../../../../src/plugins/wss/servers/WebSocketEventsServer.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport * as prettyFormat from 'pretty-format';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\nimport type { WebSocketMessageServer } from './WebSocketMessageServer';\n\n/**\n * {@link WebSocketEventsServer} configuration options.\n */\nexport interface WebSocketEventsServerConfig {\n /** Instance of a {@link WebSocketMessageServer} which can be used for broadcasting. */\n webSocketMessageServer: WebSocketMessageServer;\n}\n\n/**\n * Represents a command that connected clients can send to the {@link WebSocketEventsServer}.\n */\nexport interface Command {\n version: number;\n type: 'command';\n command: string;\n params?: any;\n}\n\n/**\n * Represents an event message.\n */\nexport interface EventMessage {\n error?: Error | string;\n type?: string;\n data?: any;\n}\n\n/**\n * Class for creating a WebSocket server to process events and reports.\n *\n * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/eventsSocketServer.ts\n *\n * @category Development server\n */\nexport class WebSocketEventsServer extends WebSocketServer {\n static readonly PROTOCOL_VERSION = 2;\n\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketHMRServer 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 * @param config Configuration object.\n */\n constructor(\n fastify: FastifyInstance,\n private config: WebSocketEventsServerConfig\n ) {\n super(fastify, '/events', {\n verifyClient: (({ origin }) => {\n return /^(https?:\\/\\/localhost|file:\\/\\/)/.test(origin);\n }) as WebSocket.VerifyClientCallbackSync,\n });\n }\n\n /**\n * Parse received command message from connected client.\n *\n * @param data Stringified command message to parse.\n * @returns Parsed command or `undefined` if parsing failed.\n */\n parseMessage(data: string): Command | undefined {\n try {\n const message = JSON.parse(data);\n if (message.version === WebSocketEventsServer.PROTOCOL_VERSION) {\n return message;\n }\n this.fastify.log.error({\n msg: 'Received message had wrong protocol version',\n message,\n });\n } catch {\n this.fastify.log.error({\n msg: 'Failed to parse the message as JSON',\n data,\n });\n }\n\n return undefined;\n }\n\n /**\n * Stringify `message` into a format that can be transported as a `string`.\n *\n * @param message Message to serialize.\n * @returns String representation of a `message` or `undefined` if serialization failed.\n */\n serializeMessage(message: EventMessage) {\n let toSerialize = message;\n if (message.error && message.error instanceof Error) {\n toSerialize = {\n ...message,\n error: prettyFormat.default(message.error, {\n escapeString: true,\n highlight: true,\n maxDepth: 3,\n min: true,\n }),\n };\n } else if (message && message.type === 'client_log') {\n toSerialize = {\n ...message,\n data: message.data.map((item: any) =>\n typeof item === 'string'\n ? item\n : prettyFormat.default(item, {\n escapeString: true,\n highlight: true,\n maxDepth: 3,\n min: true,\n plugins: [prettyFormat.plugins.ReactElement],\n })\n ),\n };\n }\n try {\n return JSON.stringify(toSerialize);\n } catch (error) {\n this.fastify.log.error({ msg: 'Failed to serialize', error });\n return undefined;\n }\n }\n\n /**\n * Broadcast event to all connected clients.\n *\n * @param event Event message to broadcast.\n */\n broadcastEvent(event: EventMessage) {\n if (!this.clients.size) {\n return;\n }\n\n const serialized = this.serializeMessage(event);\n if (!serialized) {\n return;\n }\n\n for (const [clientId, socket] of this.clients.entries()) {\n try {\n socket.send(serialized);\n } catch (error) {\n this.fastify.log.error({\n msg: 'Failed to send broadcast to client',\n clientId,\n error,\n _skipBroadcast: true,\n });\n }\n }\n }\n\n /**\n * Process new client's WebSocket connection.\n *\n * @param socket Incoming WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n this.fastify.log.debug({ msg: 'Events client connected', clientId });\n\n const onClose = () => {\n this.fastify.log.debug({ msg: 'Events client disconnected', clientId });\n socket.removeAllListeners();\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n const message = this.parseMessage(event.data.toString());\n\n if (!message) {\n return;\n }\n\n if (message.type === 'command') {\n try {\n this.config.webSocketMessageServer.broadcast(\n message.command,\n message.params\n );\n } catch (error) {\n this.fastify.log.error({\n msg: 'Failed to forward message to clients',\n error,\n });\n }\n } else {\n this.fastify.log.error({\n msg: 'Unknown message type',\n message,\n });\n }\n });\n }\n}\n"],"mapp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,OAAO,CAACgB,IAAI,KAAK,SAAS,EAAE;QAC9B,IAAI;UACF,IAAI,CAACtB,MAAM,CAAC6C,sBAAsB,CAACC,SAAS,CAC1CxC,OAAO,CAACyC,OAAO,EACfzC,OAAO,CAAC0C,MACV,CAAC;QACH,CAAC,CAAC,OAAOrC,KAAK,EAAE;UACd,IAAI,CAACZ,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;YACrBC,GAAG,EAAE,sCAAsC;YAC3CD;UACF,CAAC,CAAC;QACJ;MACF,CAAC,MAAM;QACL,IAAI,CAACZ,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;UACrBC,GAAG,EAAE,sBAAsB;UAC3BN;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketHMRServer.js","names":["URL","WebSocketServer","WebSocketHMRServer","clients","Map","nextClientId","constructor","fastify","delegate","getUriPath","send","event","platform","clientIds","data","JSON","stringify","key","socket","clientId","includes","error","log","msg","onConnection","request","searchParams","url","get","debug","close","client","set","onClose","delete","addEventListener","onClientConnected"],"sources":["../../../../src/plugins/wss/servers/WebSocketHMRServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport { URL } from 'node:url';\nimport type { FastifyInstance } from 'fastify';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\nimport type { HmrDelegate } from '../types';\n\n/**\n * Class for creating a WebSocket server for Hot Module Replacement.\n *\n * @category Development server\n */\nexport class WebSocketHMRServer extends WebSocketServer {\n private clients = new Map<\n { clientId: string; platform: string },\n WebSocket\n >();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketHMRServer 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 * @param delegate HMR delegate instance.\n */\n constructor(\n fastify: FastifyInstance,\n private delegate: HmrDelegate\n ) {\n super(fastify, delegate.getUriPath());\n }\n\n /**\n * Send action to all connected HMR clients.\n *\n * @param event Event to send to the clients.\n * @param platform Platform of clients to send the event to.\n * @param clientIds Ids of clients who should receive the event.\n */\n send(event: any, platform: string, clientIds?: string[]) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [key, socket] of this.clients) {\n if (\n key.platform !== platform ||\n !(clientIds ?? [key.clientId]).includes(key.clientId)\n ) {\n continue;\n }\n\n try {\n socket.send(data);\n } catch (error) {\n this.fastify.log.error({\n msg: 'Cannot send action to client',\n event,\n error,\n ...key,\n });\n }\n }\n }\n\n /**\n * Process new WebSocket connection from HMR client.\n *\n * @param socket Incoming HMR client's WebSocket connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { searchParams } = new URL(request.url || '', 'http://localhost');\n const platform = searchParams.get('platform');\n\n if (!platform) {\n this.fastify.log.debug({\n msg: 'HMR connection disconnected - missing platform',\n });\n socket.close();\n return;\n }\n\n const clientId = `client#${this.nextClientId++}`;\n\n const client = {\n clientId,\n platform,\n };\n\n this.clients.set(client, socket);\n\n this.fastify.log.debug({ msg: 'HMR client connected', ...client });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'HMR client disconnected',\n ...client,\n });\n this.clients.delete(client);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n\n this.delegate.onClientConnected(platform, clientId);\n }\n}\n"],"mappings":"AACA,SAASA,GAAG,QAAQ,UAAU;AAAC,SAGtBC,eAAe;AAGxB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAGvB,CAAC;EACKC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CACTC,OAAwB,EAChBC,QAAqB,EAC7B;IACA,KAAK,CAACD,OAAO,EAAEC,QAAQ,CAACC,UAAU,CAAC,CAAC,CAAC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0B,MAAM,GAAG;MACbZ,QAAQ;MACRP;IACF,CAAC;IAED,IAAI,CAACT,OAAO,CAAC6B,GAAG,CAACD,MAAM,EAAEb,MAAM,CAAC;IAEhC,IAAI,CAACX,OAAO,CAACe,GAAG,CAACO,KAAK,CAAC;MAAEN,GAAG,EAAE,sBAAsB;MAAE,GAAGQ;IAAO,CAAC,CAAC;IAElE,MAAME,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAAC1B,OAAO,CAACe,GAAG,CAACO,KAAK,CAAC;QACrBN,GAAG,EAAE,yBAAyB;QAC9B,GAAGQ;MACL,CAAC,CAAC;MACF,IAAI,CAAC5B,OAAO,CAAC+B,MAAM,CAACH,MAAM,CAAC;IAC7B,CAAC;IAEDb,MAAM,CAACiB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCf,MAAM,CAACiB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IAEzC,IAAI,CAACzB,QAAQ,CAAC4B,iBAAiB,CAACxB,QAAQ,EAAEO,QAAQ,CAAC;EACrD;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketMessageServer.js","names":["URL","WebSocketServer","WebSocketMessageServer","PROTOCOL_VERSION","isBroadcast","message","method","id","undefined","target","isRequest","isResponse","requestId","clientId","result","error","clients","Map","nextClientId","constructor","fastify","parseMessage","data","binary","log","msg","JSON","parse","version","toString","getClientSocket","socket","get","Error","handleError","errorMessage","params","send","stringify","forwardRequest","forwardResponse","processServerRequest","output","forEach","peerSocket","peerId","searchParams","upgradeReq","url","entries","reduce","acc","key","value","sendBroadcast","broadcasterId","forwarded","size","warn","broadcast","onConnection","request","client","set","debug","onClose","removeAllListeners","delete","addEventListener","event"],"sources":["../../../../src/plugins/wss/servers/WebSocketMessageServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport { URL } from 'node:url';\nimport type { FastifyInstance } from 'fastify';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Holds {@link ReactNativeMessage} `id` data.\n */\nexport interface ReactNativeIdObject {\n requestId: string;\n clientId: string;\n}\n\n/**\n * Message representation used by {@link WebSocketMessageServer}.\n */\nexport interface ReactNativeMessage {\n version?: string;\n id?: ReactNativeIdObject;\n method?: string;\n target: string;\n result?: any;\n error?: Error;\n params?: Record<string, any>;\n}\n\ntype WebSocketWithUpgradeReq = WebSocket & { upgradeReq?: IncomingMessage };\n\n/**\n * Class for creating a WebSocket server and sending messages between development server\n * and the React Native applications.\n *\n * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/messageSocketServer.ts\n *\n * @category Development server\n */\nexport class WebSocketMessageServer extends WebSocketServer {\n static readonly PROTOCOL_VERSION = 2;\n\n /**\n * Check if message is a broadcast request.\n *\n * @param message Message to check.\n * @returns True if message is a broadcast request and should be broadcasted\n * with {@link sendBroadcast}.\n */\n static isBroadcast(message: Partial<ReactNativeMessage>) {\n return (\n typeof message.method === 'string' &&\n message.id === undefined &&\n message.target === undefined\n );\n }\n\n /**\n * Check if message is a method request.\n *\n * @param message Message to check.\n * @returns True if message is a request.\n */\n static isRequest(message: Partial<ReactNativeMessage>) {\n return (\n typeof message.method === 'string' && typeof message.target === 'string'\n );\n }\n\n /**\n * Check if message is a response with results of performing some request.\n *\n * @param message Message to check.\n * @returns True if message is a response.\n */\n static isResponse(message: Partial<ReactNativeMessage>) {\n return (\n typeof message.id === 'object' &&\n typeof message.id.requestId !== 'undefined' &&\n typeof message.id.clientId === 'string' &&\n (message.result !== undefined || message.error !== undefined)\n );\n }\n\n private clients = new Map<string, WebSocketWithUpgradeReq>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketMessageServer 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, '/message');\n }\n\n /**\n * Parse stringified message into a {@link ReactNativeMessage}.\n *\n * @param data Stringified message.\n * @param binary Additional binary data if any.\n * @returns Parsed message or `undefined` if parsing failed.\n */\n parseMessage(\n data: string,\n binary: any\n ): Partial<ReactNativeMessage> | undefined {\n if (binary) {\n this.fastify.log.error({\n msg: 'Failed to parse message - expected text message, got binary',\n });\n return undefined;\n }\n try {\n const message = JSON.parse(data) as Partial<ReactNativeMessage>;\n if (\n message.version === WebSocketMessageServer.PROTOCOL_VERSION.toString()\n ) {\n return message;\n }\n this.fastify.log.error({\n msg: 'Received message had wrong protocol version',\n message,\n });\n } catch {\n this.fastify.log.error({\n msg: 'Failed to parse the message as JSON',\n data,\n });\n }\n return undefined;\n }\n\n /**\n * Get client's WebSocket connection for given `clientId`.\n * Throws if no such client is connected.\n *\n * @param clientId Id of the client.\n * @returns WebSocket connection.\n */\n getClientSocket(clientId: string) {\n const socket = this.clients.get(clientId);\n if (socket === undefined) {\n throw new Error(`Could not find client with id \"${clientId}\"`);\n }\n return socket;\n }\n\n /**\n * Process error by sending an error message to the client whose message caused the error\n * to occur.\n *\n * @param clientId Id of the client whose message caused an error.\n * @param message Original message which caused the error.\n * @param error Concrete instance of an error that occurred.\n */\n handleError(\n clientId: string,\n message: Partial<ReactNativeMessage>,\n error: Error\n ) {\n const errorMessage = {\n id: message.id,\n method: message.method,\n target: message.target,\n error: message.error === undefined ? 'undefined' : 'defined',\n params: message.params === undefined ? 'undefined' : 'defined',\n result: message.result === undefined ? 'undefined' : 'defined',\n };\n\n if (message.id === undefined) {\n this.fastify.log.error({\n msg: 'Handling message failed',\n clientId,\n error,\n errorMessage,\n });\n } else {\n try {\n const socket = this.getClientSocket(clientId);\n socket.send(\n JSON.stringify({\n version: WebSocketMessageServer.PROTOCOL_VERSION,\n error,\n id: message.id,\n })\n );\n } catch (error) {\n this.fastify.log.error('Failed to reply', {\n clientId,\n error,\n errorMessage,\n });\n }\n }\n }\n\n /**\n * Send given request `message` to it's designated client's socket based on `message.target`.\n * The target client must be connected, otherwise it will throw an error.\n *\n * @param clientId Id of the client that requested the forward.\n * @param message Message to forward.\n */\n forwardRequest(clientId: string, message: Partial<ReactNativeMessage>) {\n if (!message.target) {\n this.fastify.log.error({\n msg: 'Failed to forward request - message.target is missing',\n clientId,\n message,\n });\n return;\n }\n\n const socket = this.getClientSocket(message.target);\n socket.send(\n JSON.stringify({\n version: WebSocketMessageServer.PROTOCOL_VERSION,\n method: message.method,\n params: message.params,\n id:\n message.id === undefined\n ? undefined\n : { requestId: message.id, clientId },\n })\n );\n }\n\n /**\n * Send given response `message` to it's designated client's socket based\n * on `message.id.clientId`.\n * The target client must be connected, otherwise it will throw an error.\n *\n * @param message Message to forward.\n */\n forwardResponse(message: Partial<ReactNativeMessage>) {\n if (!message.id) {\n return;\n }\n\n const socket = this.getClientSocket(message.id.clientId);\n socket.send(\n JSON.stringify({\n version: WebSocketMessageServer.PROTOCOL_VERSION,\n result: message.result,\n error: message.error,\n id: message.id.requestId,\n })\n );\n }\n\n /**\n * Process request message targeted towards this {@link WebSocketMessageServer}\n * and send back the results.\n *\n * @param clientId Id of the client who send the message.\n * @param message The message to process by the server.\n */\n processServerRequest(clientId: string, message: Partial<ReactNativeMessage>) {\n let result: string | Record<string, Record<string, string>>;\n\n switch (message.method) {\n case 'getid':\n result = clientId;\n break;\n case 'getpeers': {\n const output: Record<string, Record<string, string>> = {};\n this.clients.forEach((peerSocket, peerId) => {\n if (clientId !== peerId) {\n const { searchParams } = new URL(peerSocket.upgradeReq?.url || '');\n output[peerId] = [...searchParams.entries()].reduce(\n (acc, [key, value]) => {\n acc[key] = value;\n return acc;\n },\n {} as Record<string, string>\n );\n }\n });\n result = output;\n break;\n }\n default:\n throw new Error(\n `Cannot process server request - unknown method ${JSON.stringify({\n clientId,\n message,\n })}`\n );\n }\n\n const socket = this.getClientSocket(clientId);\n socket.send(\n JSON.stringify({\n version: WebSocketMessageServer.PROTOCOL_VERSION,\n result,\n id: message.id,\n })\n );\n }\n\n /**\n * Broadcast given message to all connected clients.\n *\n * @param broadcasterId Id of the client who is broadcasting.\n * @param message Message to broadcast.\n */\n sendBroadcast(\n broadcasterId: string | undefined,\n message: Partial<ReactNativeMessage>\n ) {\n const forwarded = {\n version: WebSocketMessageServer.PROTOCOL_VERSION,\n method: message.method,\n params: message.params,\n };\n\n if (this.clients.size === 0) {\n this.fastify.log.warn({\n msg:\n 'No apps connected. ' +\n `Sending \"${message.method}\" to all React Native apps failed. ` +\n 'Make sure your app is running in the simulator or on a phone connected via USB.',\n });\n }\n\n for (const [clientId, socket] of this.clients) {\n if (clientId !== broadcasterId) {\n try {\n socket.send(JSON.stringify(forwarded));\n } catch (error) {\n this.fastify.log.error({\n msg: 'Failed to send broadcast',\n clientId,\n error,\n forwarded,\n });\n }\n }\n }\n }\n\n /**\n * Send method broadcast to all connected clients.\n *\n * @param method Method name to broadcast.\n * @param params Method parameters.\n */\n broadcast(method: string, params?: Record<string, any>) {\n this.sendBroadcast(undefined, { method, params });\n }\n\n /**\n * Process new client's WebSocket 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 clientId = `client#${this.nextClientId++}`;\n const client: WebSocketWithUpgradeReq = socket;\n client.upgradeReq = request;\n this.clients.set(clientId, client);\n this.fastify.log.debug({ msg: 'Message client connected', clientId });\n\n const onClose = () => {\n this.fastify.log.debug({ msg: 'Message client disconnected', clientId });\n socket.removeAllListeners();\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n const message = this.parseMessage(\n event.data.toString(),\n // @ts-ignore\n event.binary\n );\n\n if (!message) {\n this.fastify.log.error({\n msg: 'Received message not matching protocol',\n clientId,\n message,\n });\n return;\n }\n\n try {\n if (WebSocketMessageServer.isBroadcast(message)) {\n this.sendBroadcast(clientId, message);\n } else if (WebSocketMessageServer.isRequest(message)) {\n if (message.target === 'server') {\n this.processServerRequest(clientId, message);\n } else {\n this.forwardRequest(clientId, message);\n }\n } else if (WebSocketMessageServer.isResponse(message)) {\n this.forwardResponse(message);\n } else {\n throw new Error(\n `Invalid message, did not match the protocol ${JSON.stringify({\n clientId,\n message,\n })}`\n );\n }\n } catch (error) {\n this.handleError(clientId, message, error as Error);\n }\n });\n }\n}\n"],"mappings":"AACA,SAASA,GAAG,QAAQ,UAAU;AAAC,SAGtBC,eAAe;AAExB;AACA;AACA;AAMA;AACA;AACA;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,SAASD,eAAe,CAAC;EAC1D,OAAgBE,gBAAgB,GAAG,CAAC;;EAEpC;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,WAAWA,CAACC,OAAoC,EAAE;IACvD,OACE,OAAOA,OAAO,CAACC,MAAM,KAAK,QAAQ,IAClCD,OAAO,CAACE,EAAE,KAAKC,SAAS,IACxBH,OAAO,CAACI,MAAM,KAAKD,SAAS;EAEhC;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOE,SAASA,CAACL,OAAoC,EAAE;IACrD,OACE,OAAOA,OAAO,CAACC,MAAM,KAAK,QAAQ,IAAI,OAAOD,OAAO,CAACI,MAAM,KAAK,QAAQ;EAE5E;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOE,UAAUA,CAACN,OAAoC,EAAE;IACtD,OACE,OAAOA,OAAO,CAACE,EAAE,KAAK,QAAQ,IAC9B,OAAOF,OAAO,CAACE,EAAE,CAACK,SAAS,KAAK,WAAW,IAC3C,OAAOP,OAAO,CAACE,EAAE,CAACM,QAAQ,KAAK,QAAQ,KACtCR,OAAO,CAACS,MAAM,KAAKN,SAAS,IAAIH,OAAO,CAACU,KAAK,KAAKP,SAAS,CAAC;EAEjE;EAEQQ,OAAO,GAAG,IAAIC,GAAG,CAAkC,CAAC;EACpDC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;E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;IACF,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/wss/types.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\n\n/**\n * Delegate with implementation for HMR-specific functions.\n */\nexport interface HmrDelegate {\n /** Get URI under which HMR server will be running, e.g: `/hmr` */\n getUriPath: () => string;\n\n /**\n * Callback for when the new HMR client is connected.\n *\n * Useful for running initial synchronization or any other side effect.\n *\n * @param platform Platform of the connected client.\n * @param clientId Id of the connected client.\n */\n onClientConnected: (platform: string, clientId: string) => void;\n}\n\nexport interface WebSocketServerInterface {\n shouldUpgrade(pathname: string): boolean;\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer): void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketRouter","WebSocketServerAdapter","WebSocketApiServer","WebSocketDebuggerServer","WebSocketDevClientServer","WebSocketEventsServer","WebSocketHMRServer","WebSocketMessageServer","WS_DEVICE_URL","WS_DEBUGGER_URL","wssPlugin","instance","options","delegate","router","debuggerServer","devClientServer","messageServer","eventsServer","webSocketMessageServer","apiServer","hmrServer","hmr","deviceConnectionServer","endpoints","debuggerConnectionServer","registerServer","decorate","name"],"sources":["../../../src/plugins/wss/wssPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { WebSocketRouter } from './WebSocketRouter';\nimport { WebSocketServerAdapter } from './WebSocketServerAdapter';\nimport { WebSocketApiServer } from './servers/WebSocketApiServer';\nimport { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';\nimport { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';\nimport { WebSocketEventsServer } from './servers/WebSocketEventsServer';\nimport { WebSocketHMRServer } from './servers/WebSocketHMRServer';\nimport { WebSocketMessageServer } from './servers/WebSocketMessageServer';\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n wss: {\n debuggerServer: WebSocketDebuggerServer;\n devClientServer: WebSocketDevClientServer;\n messageServer: WebSocketMessageServer;\n eventsServer: WebSocketEventsServer;\n apiServer: WebSocketApiServer;\n hmrServer: WebSocketHMRServer;\n deviceConnectionServer: WebSocketServerAdapter;\n debuggerConnectionServer: WebSocketServerAdapter;\n router: WebSocketRouter;\n };\n }\n}\n\n/**\n * Defined in @react-native/dev-middleware\n * Reference: https://github.com/facebook/react-native/blob/main/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js\n */\nconst WS_DEVICE_URL = '/inspector/device';\nconst WS_DEBUGGER_URL = '/inspector/debug';\n\nasync function wssPlugin(\n instance: FastifyInstance,\n {\n options,\n delegate,\n }: {\n options: Server.Options;\n delegate: Server.Delegate;\n }\n) {\n const router = new WebSocketRouter(instance);\n\n const debuggerServer = new WebSocketDebuggerServer(instance);\n const devClientServer = new WebSocketDevClientServer(instance);\n const messageServer = new WebSocketMessageServer(instance);\n const eventsServer = new WebSocketEventsServer(instance, {\n webSocketMessageServer: messageServer,\n });\n const apiServer = new WebSocketApiServer(instance);\n const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);\n\n // @react-native/dev-middleware servers\n const deviceConnectionServer = new WebSocketServerAdapter(\n instance,\n WS_DEVICE_URL,\n options.endpoints?.[WS_DEVICE_URL]\n );\n\n const debuggerConnectionServer = new WebSocketServerAdapter(\n instance,\n WS_DEBUGGER_URL,\n options.endpoints?.[WS_DEBUGGER_URL]\n );\n\n router.registerServer(debuggerServer);\n router.registerServer(devClientServer);\n router.registerServer(messageServer);\n router.registerServer(eventsServer);\n router.registerServer(apiServer);\n router.registerServer(hmrServer);\n router.registerServer(deviceConnectionServer);\n router.registerServer(debuggerConnectionServer);\n\n instance.decorate('wss', {\n debuggerServer,\n devClientServer,\n messageServer,\n eventsServer,\n apiServer,\n hmrServer,\n deviceConnectionServer,\n debuggerConnectionServer,\n router,\n });\n}\n\nexport default fastifyPlugin(wssPlugin, {\n name: 'wss-plugin',\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,eAAe;AAAA,SACfC,sBAAsB;AAAA,SACtBC,kBAAkB;AAAA,SAClBC,uBAAuB;AAAA,SACvBC,wBAAwB;AAAA,SACxBC,qBAAqB;AAAA,SACrBC,kBAAkB;AAAA,SAClBC,sBAAsB;AAkB/B;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAG,mBAAmB;AACzC,MAAMC,eAAe,GAAG,kBAAkB;AAE1C,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EACEC,OAAO;EACPC;AAIF,CAAC,EACD;EACA,MAAMC,MAAM,GAAG,IAAId,eAAe,CAACW,QAAQ,CAAC;EAE5C,MAAMI,cAAc,GAAG,IAAIZ,uBAAuB,CAACQ,QAAQ,CAAC;EAC5D,MAAMK,eAAe,GAAG,IAAIZ,wBAAwB,CAACO,QAAQ,CAAC;EAC9D,MAAMM,aAAa,GAAG,IAAIV,sBAAsB,CAACI,QAAQ,CAAC;EAC1D,MAAMO,YAAY,GAAG,IAAIb,qBAAqB,CAACM,QAAQ,EAAE;IACvDQ,sBAAsB,EAAEF;EAC1B,CAAC,CAAC;EACF,MAAMG,SAAS,GAAG,IAAIlB,kBAAkB,CAACS,QAAQ,CAAC;EAClD,MAAMU,SAAS,GAAG,IAAIf,kBAAkB,CAACK,QAAQ,EAAEE,QAAQ,CAACS,GAAG,CAAC;;EAEhE;EACA,MAAMC,sBAAsB,GAAG,IAAItB,sBAAsB,CACvDU,QAAQ,EACRH,aAAa,EACbI,OAAO,CAACY,SAAS,GAAGhB,aAAa,CACnC,CAAC;EAED,MAAMiB,wBAAwB,GAAG,IAAIxB,sBAAsB,CACzDU,QAAQ,EACRF,eAAe,EACfG,OAAO,CAACY,SAAS,GAAGf,eAAe,CACrC,CAAC;EAEDK,MAAM,CAACY,cAAc,CAACX,cAAc,CAAC;EACrCD,MAAM,CAACY,cAAc,CAACV,eAAe,CAAC;EACtCF,MAAM,CAACY,cAAc,CAACT,aAAa,CAAC;EACpCH,MAAM,CAACY,cAAc,CAACR,YAAY,CAAC;EACnCJ,MAAM,CAACY,cAAc,CAACN,SAAS,CAAC;EAChCN,MAAM,CAACY,cAAc,CAACL,SAAS,CAAC;EAChCP,MAAM,CAACY,cAAc,CAACH,sBAAsB,CAAC;EAC7CT,MAAM,CAACY,cAAc,CAACD,wBAAwB,CAAC;EAE/Cd,QAAQ,CAACgB,QAAQ,CAAC,KAAK,EAAE;IACvBZ,cAAc;IACdC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZE,SAAS;IACTC,SAAS;IACTE,sBAAsB;IACtBE,wBAAwB;IACxBX;EACF,CAAC,CAAC;AACJ;AAEA,eAAef,aAAa,CAACW,SAAS,EAAE;EACtCkB,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 experiments?: Experiments;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate;\n }\n\n export interface Experiments {\n experimentalDebugger?: boolean;\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;AA0KvB;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":[]}
|
|
File without changes
|