@callstack/repack-dev-server 1.0.2 → 4.0.0-rc.0
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 +16 -0
- package/LICENSE +21 -0
- package/dist/createServer.d.ts +1 -1
- package/dist/createServer.js +16 -17
- package/dist/createServer.js.map +1 -1
- package/dist/plugins/api/apiPlugin.js +3 -9
- package/dist/plugins/api/apiPlugin.js.map +1 -1
- package/dist/plugins/api/index.js.map +1 -1
- package/dist/plugins/compiler/compilerPlugin.d.ts +4 -3
- package/dist/plugins/compiler/compilerPlugin.js +8 -18
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
- package/dist/plugins/compiler/index.js.map +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.d.ts +4 -3
- package/dist/plugins/devtools/devtoolsPlugin.js +6 -8
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
- package/dist/plugins/devtools/index.js.map +1 -1
- package/dist/plugins/favicon/faviconPlugin.d.ts +3 -2
- package/dist/plugins/favicon/faviconPlugin.js +2 -3
- 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.d.ts +3 -2
- package/dist/plugins/multipart/multipartPlugin.js +1 -14
- package/dist/plugins/multipart/multipartPlugin.js.map +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +13 -32
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
- package/dist/plugins/symbolicate/index.js.map +1 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +4 -3
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +2 -4
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -1
- package/dist/plugins/wss/WebSocketRouter.js +2 -6
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
- package/dist/plugins/wss/WebSocketServer.js +2 -5
- package/dist/plugins/wss/WebSocketServer.js.map +1 -1
- package/dist/plugins/wss/index.js.map +1 -1
- package/dist/plugins/wss/servers/HermesInspectorProxy.js +1 -19
- package/dist/plugins/wss/servers/HermesInspectorProxy.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js +5 -11
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +6 -20
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +3 -12
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketEventsServer.js +18 -25
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +3 -13
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +21 -51
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -1
- package/dist/plugins/wss/wssPlugin.d.ts +4 -3
- package/dist/plugins/wss/wssPlugin.js +0 -2
- package/dist/plugins/wss/wssPlugin.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +9 -34
- package/dist/types.js.map +1 -1
- package/package.json +26 -29
- package/docs/README.md +0 -28
- package/docs/enums/Internal.EventTypes.md +0 -41
- package/docs/functions/createServer.md +0 -21
- package/docs/interfaces/CodeFrame.md +0 -48
- package/docs/interfaces/CompilerDelegate.md +0 -83
- package/docs/interfaces/HmrDelegate.md +0 -51
- package/docs/interfaces/InputStackFrame.md +0 -76
- package/docs/interfaces/ProgressData.md +0 -34
- package/docs/interfaces/ReactNativeStackFrame.md +0 -58
- package/docs/interfaces/Server.Api.Asset.md +0 -36
- package/docs/interfaces/Server.Api.CompilationStats.md +0 -9
- package/docs/interfaces/Server.Api.Delegate.md +0 -75
- package/docs/interfaces/Server.Config.md +0 -49
- package/docs/interfaces/Server.Delegate.md +0 -88
- package/docs/interfaces/Server.DelegateContext.md +0 -134
- package/docs/interfaces/Server.LoggerDelegate.md +0 -33
- package/docs/interfaces/Server.MessagesDelegate.md +0 -44
- package/docs/interfaces/Server.Options.md +0 -70
- package/docs/interfaces/StackFrame.md +0 -85
- package/docs/interfaces/SymbolicatorDelegate.md +0 -77
- package/docs/interfaces/SymbolicatorResults.md +0 -30
- package/docs/modules/Internal.md +0 -11
- package/docs/modules/Server.Api.md +0 -11
- package/docs/modules/Server.md +0 -16
- package/docs/types/SendProgress.md +0 -26
|
@@ -7,14 +7,12 @@ const WS_DEBUGGER_URL = '/inspector/debug';
|
|
|
7
7
|
export class HermesInspectorProxy extends WebSocketServer {
|
|
8
8
|
devices = new Map();
|
|
9
9
|
deviceCounter = 0;
|
|
10
|
-
|
|
11
10
|
constructor(fastify, config) {
|
|
12
11
|
super(fastify, [WS_DEVICE_URL, WS_DEBUGGER_URL]);
|
|
13
12
|
this.config = config;
|
|
14
13
|
this.serverHost = `${this.config.host || 'localhost'}:${this.config.port}`;
|
|
15
14
|
this.setup();
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
setup() {
|
|
19
17
|
const onSend = (_request, reply, _payload, done) => {
|
|
20
18
|
reply.headers({
|
|
@@ -24,7 +22,6 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
24
22
|
});
|
|
25
23
|
done();
|
|
26
24
|
};
|
|
27
|
-
|
|
28
25
|
this.fastify.get('/json/version', {
|
|
29
26
|
onSend
|
|
30
27
|
}, async () => {
|
|
@@ -33,21 +30,16 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
33
30
|
'Protocol-Version': '1.1'
|
|
34
31
|
};
|
|
35
32
|
});
|
|
36
|
-
|
|
37
33
|
const pageListHandler = async () => {
|
|
38
34
|
const pages = [];
|
|
39
|
-
|
|
40
35
|
for (const [deviceId, device] of this.devices) {
|
|
41
36
|
const devicePages = device.getPagesList();
|
|
42
|
-
|
|
43
37
|
for (const page of devicePages) {
|
|
44
38
|
pages.push(this.buildPageDescription(deviceId, page));
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
return pages;
|
|
49
42
|
};
|
|
50
|
-
|
|
51
43
|
this.fastify.get('/json/list', {
|
|
52
44
|
onSend
|
|
53
45
|
}, pageListHandler);
|
|
@@ -56,7 +48,6 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
56
48
|
logLevel: 'silent'
|
|
57
49
|
}, pageListHandler);
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
buildPageDescription(deviceId, page) {
|
|
61
52
|
const debuggerUrl = `${this.serverHost}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;
|
|
62
53
|
const webSocketDebuggerUrl = 'ws://' + debuggerUrl;
|
|
@@ -72,14 +63,13 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
72
63
|
vm: page.vm
|
|
73
64
|
};
|
|
74
65
|
}
|
|
66
|
+
|
|
75
67
|
/**
|
|
76
68
|
* Process new WebSocket connection from device.
|
|
77
69
|
*
|
|
78
70
|
* @param socket Incoming device's WebSocket connection.
|
|
79
71
|
* @param request Upgrade request for the connection.
|
|
80
72
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
73
|
onConnection(socket, request) {
|
|
84
74
|
try {
|
|
85
75
|
const {
|
|
@@ -88,7 +78,6 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
88
78
|
const {
|
|
89
79
|
searchParams
|
|
90
80
|
} = new URL(url, 'http://localhost');
|
|
91
|
-
|
|
92
81
|
if (url.startsWith('/inspector/device')) {
|
|
93
82
|
const deviceName = searchParams.get('name') ?? 'Unknown';
|
|
94
83
|
const appName = searchParams.get('app') ?? 'Unknown';
|
|
@@ -98,7 +87,6 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
98
87
|
msg: 'Hermes device connected',
|
|
99
88
|
deviceId
|
|
100
89
|
});
|
|
101
|
-
|
|
102
90
|
const onClose = () => {
|
|
103
91
|
this.fastify.log.info({
|
|
104
92
|
msg: 'Hermes device disconnected',
|
|
@@ -106,23 +94,18 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
106
94
|
});
|
|
107
95
|
this.devices.delete(deviceId);
|
|
108
96
|
};
|
|
109
|
-
|
|
110
97
|
socket.addEventListener('error', onClose);
|
|
111
98
|
socket.addEventListener('close', onClose);
|
|
112
99
|
} else {
|
|
113
100
|
const deviceId = searchParams.get('device') ?? undefined;
|
|
114
101
|
const pageId = searchParams.get('page') ?? undefined;
|
|
115
|
-
|
|
116
102
|
if (deviceId === undefined || pageId === undefined) {
|
|
117
103
|
throw new Error('Incorrect URL - must provide device and page IDs');
|
|
118
104
|
}
|
|
119
|
-
|
|
120
105
|
const device = this.devices.get(parseInt(deviceId, 10));
|
|
121
|
-
|
|
122
106
|
if (!device) {
|
|
123
107
|
throw new Error('Unknown device with ID ' + deviceId);
|
|
124
108
|
}
|
|
125
|
-
|
|
126
109
|
device.handleDebuggerConnection(socket, pageId);
|
|
127
110
|
}
|
|
128
111
|
} catch (error) {
|
|
@@ -133,6 +116,5 @@ export class HermesInspectorProxy extends WebSocketServer {
|
|
|
133
116
|
socket.close(1011, error.toString());
|
|
134
117
|
}
|
|
135
118
|
}
|
|
136
|
-
|
|
137
119
|
}
|
|
138
120
|
//# sourceMappingURL=HermesInspectorProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HermesInspectorProxy.js","names":["URL","WebSocketServer","Device","WS_DEVICE_URL","WS_DEBUGGER_URL","HermesInspectorProxy","devices","Map","deviceCounter","constructor","fastify","config","serverHost","host","port","setup","onSend","_request","reply","_payload","done","headers","Connection","get","Browser","pageListHandler","pages","deviceId","device","devicePages","getPagesList","page","push","buildPageDescription","logLevel","debuggerUrl","id","webSocketDebuggerUrl","devtoolsFrontendUrl","encodeURIComponent","description","app","title","faviconUrl","type","vm","onConnection","socket","request","url","searchParams","startsWith","deviceName","appName","set","rootDir","log","info","msg","onClose","delete","addEventListener","undefined","pageId","Error","parseInt","handleDebuggerConnection","error","message","close","toString"],"sources":["../../../../src/plugins/wss/servers/HermesInspectorProxy.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport { URL } from 'url';\nimport WebSocket from 'ws';\nimport type {\n FastifyInstance,\n FastifyReply,\n FastifyRequest,\n LogLevel,\n} from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\nimport { Server } from '../../../types';\n// @ts-ignore\nimport Device from '../../../../vendor/metro-inspector-proxy/src/Device.js';\n\nconst WS_DEVICE_URL = '/inspector/device';\nconst WS_DEBUGGER_URL = '/inspector/debug';\n\ninterface PageDescription {\n id: string;\n description: string;\n title: string;\n faviconUrl: string;\n devtoolsFrontendUrl: string;\n type: string;\n webSocketDebuggerUrl: string;\n vm?: string;\n}\n\ninterface Page {\n id: string;\n title: string;\n app: string;\n vm?: string;\n}\n\nexport interface InspectorProxyConfig\n extends Pick<Server.Options, 'port' | 'host' | 'rootDir'> {}\n\nexport class HermesInspectorProxy extends WebSocketServer {\n private devices = new Map<number, any>();\n private deviceCounter = 0;\n public readonly serverHost: string;\n\n constructor(fastify: FastifyInstance
|
|
1
|
+
{"version":3,"file":"HermesInspectorProxy.js","names":["URL","WebSocketServer","Device","WS_DEVICE_URL","WS_DEBUGGER_URL","HermesInspectorProxy","devices","Map","deviceCounter","constructor","fastify","config","serverHost","host","port","setup","onSend","_request","reply","_payload","done","headers","Connection","get","Browser","pageListHandler","pages","deviceId","device","devicePages","getPagesList","page","push","buildPageDescription","logLevel","debuggerUrl","id","webSocketDebuggerUrl","devtoolsFrontendUrl","encodeURIComponent","description","app","title","faviconUrl","type","vm","onConnection","socket","request","url","searchParams","startsWith","deviceName","appName","set","rootDir","log","info","msg","onClose","delete","addEventListener","undefined","pageId","Error","parseInt","handleDebuggerConnection","error","message","close","toString"],"sources":["../../../../src/plugins/wss/servers/HermesInspectorProxy.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport { URL } from 'url';\nimport WebSocket from 'ws';\nimport type {\n FastifyInstance,\n FastifyReply,\n FastifyRequest,\n LogLevel,\n} from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\nimport { Server } from '../../../types';\n// @ts-ignore\nimport Device from '../../../../vendor/metro-inspector-proxy/src/Device.js';\n\nconst WS_DEVICE_URL = '/inspector/device';\nconst WS_DEBUGGER_URL = '/inspector/debug';\n\ninterface PageDescription {\n id: string;\n description: string;\n title: string;\n faviconUrl: string;\n devtoolsFrontendUrl: string;\n type: string;\n webSocketDebuggerUrl: string;\n vm?: string;\n}\n\ninterface Page {\n id: string;\n title: string;\n app: string;\n vm?: string;\n}\n\nexport interface InspectorProxyConfig\n extends Pick<Server.Options, 'port' | 'host' | 'rootDir'> {}\n\nexport class HermesInspectorProxy extends WebSocketServer {\n private devices = new Map<number, any>();\n private deviceCounter = 0;\n public readonly serverHost: string;\n\n constructor(\n fastify: FastifyInstance,\n private config: InspectorProxyConfig\n ) {\n super(fastify, [WS_DEVICE_URL, WS_DEBUGGER_URL]);\n this.serverHost = `${this.config.host || 'localhost'}:${this.config.port}`;\n this.setup();\n }\n\n private setup() {\n const onSend = (\n _request: FastifyRequest,\n reply: FastifyReply,\n _payload: unknown,\n done: () => void\n ) => {\n reply.headers({\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Cache-Control': 'no-cache',\n Connection: 'close',\n });\n done();\n };\n\n this.fastify.get('/json/version', { onSend }, async () => {\n return {\n Browser: 'Mobile JavaScript',\n 'Protocol-Version': '1.1',\n };\n });\n\n const pageListHandler = async () => {\n const pages: PageDescription[] = [];\n for (const [deviceId, device] of this.devices) {\n const devicePages = device.getPagesList();\n for (const page of devicePages) {\n pages.push(this.buildPageDescription(deviceId, page));\n }\n }\n\n return pages;\n };\n\n this.fastify.get('/json/list', { onSend }, pageListHandler);\n this.fastify.get(\n '/json',\n { onSend, logLevel: 'silent' as LogLevel },\n pageListHandler\n );\n }\n\n private buildPageDescription(deviceId: number, page: Page) {\n const debuggerUrl = `${this.serverHost}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;\n const webSocketDebuggerUrl = 'ws://' + debuggerUrl;\n const devtoolsFrontendUrl =\n 'chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=' +\n encodeURIComponent(debuggerUrl);\n return {\n id: `${deviceId}-${page.id}`,\n description: page.app,\n title: page.title,\n faviconUrl: 'https://reactjs.org/favicon.ico',\n devtoolsFrontendUrl,\n type: 'node',\n webSocketDebuggerUrl,\n vm: page.vm,\n };\n }\n\n /**\n * Process new WebSocket connection from device.\n *\n * @param socket Incoming device's WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n try {\n const { url = '' } = request;\n const { searchParams } = new URL(url, 'http://localhost');\n\n if (url.startsWith('/inspector/device')) {\n const deviceName = searchParams.get('name') ?? 'Unknown';\n const appName = searchParams.get('app') ?? 'Unknown';\n const deviceId = this.deviceCounter++;\n\n this.devices.set(\n deviceId,\n new Device(deviceId, deviceName, appName, socket, this.config.rootDir)\n );\n\n this.fastify.log.info({ msg: 'Hermes device connected', deviceId });\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'Hermes device disconnected',\n deviceId,\n });\n this.devices.delete(deviceId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n } else {\n const deviceId = searchParams.get('device') ?? undefined;\n const pageId = searchParams.get('page') ?? undefined;\n\n if (deviceId === undefined || pageId === undefined) {\n throw new Error('Incorrect URL - must provide device and page IDs');\n }\n\n const device = this.devices.get(parseInt(deviceId, 10));\n if (!device) {\n throw new Error('Unknown device with ID ' + deviceId);\n }\n\n device.handleDebuggerConnection(socket, pageId);\n }\n } catch (error) {\n this.fastify.log.error({\n msg: 'Failed to establish connection with Hermes device',\n error: (error as Error).message,\n });\n socket.close(1011, (error as Error).to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I,CAACtB,OAAO,CAACiB,GAAG,CAAC0C,QAAQ,CAACtC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI,CAACC,MAAM,EAAE;UACX,MAAM,IAAIoC,KAAK,CAAC,yBAAyB,GAAGrC,QAAQ,CAAC;QACvD;QAEAC,MAAM,CAACsC,wBAAwB,CAACnB,MAAM,EAAEgB,MAAM,CAAC;MACjD;IACF,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,IAAI,CAACzD,OAAO,CAAC8C,GAAG,CAACW,KAAK,CAAC;QACrBT,GAAG,EAAE,mDAAmD;QACxDS,KAAK,EAAGA,KAAK,CAAWC;MAC1B,CAAC,CAAC;MACFrB,MAAM,CAACsB,KAAK,CAAC,IAAI,EAAGF,KAAK,CAAWG,QAAQ,CAAC,CAAC,CAAC;IACjD;EACF;AACF"}
|
|
@@ -5,44 +5,41 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
5
5
|
*
|
|
6
6
|
* @category Development server
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export class WebSocketApiServer extends WebSocketServer {
|
|
10
9
|
clients = new Map();
|
|
11
10
|
nextClientId = 0;
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
|
|
14
14
|
* Any logging information, will be passed through standard `fastify.log` API.
|
|
15
15
|
*
|
|
16
16
|
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
constructor(fastify) {
|
|
20
19
|
super(fastify, '/api');
|
|
21
20
|
}
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* Send message to all connected API clients.
|
|
24
24
|
*
|
|
25
25
|
* @param event Event string or object to send.
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
27
|
send(event) {
|
|
30
28
|
const data = typeof event === 'string' ? event : JSON.stringify(event);
|
|
31
|
-
|
|
32
29
|
for (const [, socket] of this.clients.entries()) {
|
|
33
30
|
try {
|
|
34
31
|
socket.send(data);
|
|
35
|
-
} catch {
|
|
32
|
+
} catch {
|
|
33
|
+
// NOOP
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
}
|
|
37
|
+
|
|
39
38
|
/**
|
|
40
39
|
* Process new WebSocket connection from client application.
|
|
41
40
|
*
|
|
42
41
|
* @param socket Incoming client's WebSocket connection.
|
|
43
42
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
43
|
onConnection(socket) {
|
|
47
44
|
const clientId = `client#${this.nextClientId++}`;
|
|
48
45
|
this.clients.set(clientId, socket);
|
|
@@ -51,7 +48,6 @@ export class WebSocketApiServer extends WebSocketServer {
|
|
|
51
48
|
clientId
|
|
52
49
|
});
|
|
53
50
|
this.clients.set(clientId, socket);
|
|
54
|
-
|
|
55
51
|
const onClose = () => {
|
|
56
52
|
this.fastify.log.info({
|
|
57
53
|
msg: 'API client disconnected',
|
|
@@ -59,10 +55,8 @@ export class WebSocketApiServer extends WebSocketServer {
|
|
|
59
55
|
});
|
|
60
56
|
this.clients.delete(clientId);
|
|
61
57
|
};
|
|
62
|
-
|
|
63
58
|
socket.addEventListener('error', onClose);
|
|
64
59
|
socket.addEventListener('close', onClose);
|
|
65
60
|
}
|
|
66
|
-
|
|
67
61
|
}
|
|
68
62
|
//# sourceMappingURL=WebSocketApiServer.js.map
|
|
@@ -1 +1 @@
|
|
|
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","info","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport 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.info({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\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,
|
|
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","info","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport 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.info({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\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,GAAI,UAAS,IAAI,CAACX,YAAY,EAAG,EAAC;IAChD,IAAI,CAACF,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,IAAI,CAACN,OAAO,CAACW,GAAG,CAACC,IAAI,CAAC;MAAEC,GAAG,EAAE,sBAAsB;MAAEJ;IAAS,CAAC,CAAC;IAChE,IAAI,CAACb,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,MAAMQ,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACd,OAAO,CAACW,GAAG,CAACC,IAAI,CAAC;QACpBC,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"}
|
|
@@ -8,7 +8,6 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @category Development server
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
export class WebSocketDebuggerServer extends WebSocketServer {
|
|
13
12
|
/**
|
|
14
13
|
* A WebSocket connection with the debugger UI.
|
|
@@ -27,25 +26,23 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
27
26
|
constructor(fastify) {
|
|
28
27
|
super(fastify, '/debugger-proxy');
|
|
29
28
|
}
|
|
29
|
+
|
|
30
30
|
/**
|
|
31
31
|
* Check if debugger UI is connected to the WebSocketDebuggerServer.
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
33
|
isDebuggerConnected() {
|
|
36
34
|
return Boolean(this.debuggerSocket);
|
|
37
35
|
}
|
|
36
|
+
|
|
38
37
|
/**
|
|
39
38
|
* Send a message to a given WebSocket connection.
|
|
40
39
|
*
|
|
41
40
|
* @param socket WebSocket connection to send the message to.
|
|
42
41
|
* @param message Message to send.
|
|
43
42
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
43
|
send(socket, message) {
|
|
47
44
|
try {
|
|
48
|
-
socket
|
|
45
|
+
socket?.send(message);
|
|
49
46
|
} catch (error) {
|
|
50
47
|
this.fastify.log.warn({
|
|
51
48
|
msg: 'Failed to send data to socket',
|
|
@@ -53,6 +50,7 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
52
|
}
|
|
53
|
+
|
|
56
54
|
/**
|
|
57
55
|
* Process new WebSocket connection. The upgrade request should contain `role` query param
|
|
58
56
|
* for determining the type of the connection.
|
|
@@ -60,13 +58,10 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
60
58
|
* @param socket Incoming WebSocket connection.
|
|
61
59
|
* @param request Upgrade request for the connection.
|
|
62
60
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
61
|
onConnection(socket, request) {
|
|
66
62
|
const {
|
|
67
63
|
url = ''
|
|
68
64
|
} = request;
|
|
69
|
-
|
|
70
65
|
if (url.indexOf('role=debugger') >= 0) {
|
|
71
66
|
this.fastify.log.info({
|
|
72
67
|
msg: 'Chrome Remote JS debugger connected'
|
|
@@ -81,34 +76,29 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
81
76
|
socket.close(1011, 'Missing role param');
|
|
82
77
|
}
|
|
83
78
|
}
|
|
79
|
+
|
|
84
80
|
/**
|
|
85
81
|
* Process new WebSocket connection from Debugger UI (Remote JS Debugger).
|
|
86
82
|
* If there's already open connection, the new one gets closed automatically.
|
|
87
83
|
*
|
|
88
84
|
* @param socket Incoming debugger WebSocket connection.
|
|
89
85
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
86
|
onDebuggerConnection(socket) {
|
|
93
87
|
if (this.debuggerSocket) {
|
|
94
88
|
socket.close(1011, 'Another debugger is already connected');
|
|
95
89
|
return;
|
|
96
90
|
}
|
|
97
|
-
|
|
98
91
|
this.debuggerSocket = socket;
|
|
99
|
-
|
|
100
92
|
const onClose = () => {
|
|
101
93
|
this.fastify.log.info({
|
|
102
94
|
msg: 'Chrome Remote JS debugger disconnected'
|
|
103
95
|
});
|
|
104
96
|
this.debuggerSocket = undefined;
|
|
105
|
-
|
|
106
97
|
if (this.clientSocket) {
|
|
107
98
|
this.clientSocket.removeAllListeners();
|
|
108
99
|
this.clientSocket.close(1011, 'Debugger was disconnected');
|
|
109
100
|
}
|
|
110
101
|
};
|
|
111
|
-
|
|
112
102
|
this.debuggerSocket.addEventListener('error', onClose);
|
|
113
103
|
this.debuggerSocket.addEventListener('close', onClose);
|
|
114
104
|
this.debuggerSocket.addEventListener('message', ({
|
|
@@ -117,21 +107,19 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
117
107
|
this.send(this.clientSocket, data.toString());
|
|
118
108
|
});
|
|
119
109
|
}
|
|
110
|
+
|
|
120
111
|
/**
|
|
121
112
|
* Process new WebSocket connection from React Native app (client)
|
|
122
113
|
* and close any previous connection.
|
|
123
114
|
*
|
|
124
115
|
* @param socket Incoming client WebSocket connection.
|
|
125
116
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
117
|
onClientConnection(socket) {
|
|
129
118
|
if (this.clientSocket) {
|
|
130
119
|
this.clientSocket.removeAllListeners();
|
|
131
120
|
this.clientSocket.close(1011, 'Another client is connected');
|
|
132
121
|
this.clientSocket = undefined;
|
|
133
122
|
}
|
|
134
|
-
|
|
135
123
|
const onClose = () => {
|
|
136
124
|
this.fastify.log.info({
|
|
137
125
|
msg: 'React Native app disconnected from debugger'
|
|
@@ -141,7 +129,6 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
141
129
|
method: '$disconnected'
|
|
142
130
|
}));
|
|
143
131
|
};
|
|
144
|
-
|
|
145
132
|
this.clientSocket = socket;
|
|
146
133
|
this.clientSocket.addEventListener('error', onClose);
|
|
147
134
|
this.clientSocket.addEventListener('close', onClose);
|
|
@@ -151,6 +138,5 @@ export class WebSocketDebuggerServer extends WebSocketServer {
|
|
|
151
138
|
this.send(this.debuggerSocket, data.toString());
|
|
152
139
|
});
|
|
153
140
|
}
|
|
154
|
-
|
|
155
141
|
}
|
|
156
142
|
//# sourceMappingURL=WebSocketDebuggerServer.js.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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;QAAEL,GAAG,EAAE;MAAyC,CAAC,CAAC;MACxE,I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,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"}
|
|
@@ -5,33 +5,30 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
5
5
|
*
|
|
6
6
|
* @category Development server
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export class WebSocketDevClientServer extends WebSocketServer {
|
|
10
9
|
clients = new Map();
|
|
11
10
|
nextClientId = 0;
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Create new instance of WebSocketDevClientServer and attach it to the given Fastify instance.
|
|
14
14
|
* Any logging information, will be passed through standard `fastify.log` API.
|
|
15
15
|
*
|
|
16
16
|
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
constructor(fastify) {
|
|
20
19
|
super(fastify, '/__client');
|
|
21
20
|
}
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* Process client message.
|
|
24
24
|
*
|
|
25
25
|
* @param message Stringified client message.
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
27
|
processMessage(message) {
|
|
30
28
|
const {
|
|
31
29
|
type,
|
|
32
30
|
...body
|
|
33
31
|
} = JSON.parse(message);
|
|
34
|
-
|
|
35
32
|
switch (type) {
|
|
36
33
|
case 'client-log':
|
|
37
34
|
if (body.level === 'error') {
|
|
@@ -50,9 +47,7 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
50
47
|
msg: body.data
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
break;
|
|
55
|
-
|
|
56
51
|
default:
|
|
57
52
|
this.fastify.log.warn({
|
|
58
53
|
msg: 'Unknown client message',
|
|
@@ -60,13 +55,12 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
60
55
|
});
|
|
61
56
|
}
|
|
62
57
|
}
|
|
58
|
+
|
|
63
59
|
/**
|
|
64
60
|
* Process new WebSocket connection from client application.
|
|
65
61
|
*
|
|
66
62
|
* @param socket Incoming client's WebSocket connection.
|
|
67
63
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
64
|
onConnection(socket) {
|
|
71
65
|
const clientId = `client#${this.nextClientId++}`;
|
|
72
66
|
this.clients.set(clientId, socket);
|
|
@@ -75,7 +69,6 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
75
69
|
clientId
|
|
76
70
|
});
|
|
77
71
|
this.clients.set(clientId, socket);
|
|
78
|
-
|
|
79
72
|
const onClose = () => {
|
|
80
73
|
this.fastify.log.info({
|
|
81
74
|
msg: 'React Native client disconnected',
|
|
@@ -83,13 +76,11 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
83
76
|
});
|
|
84
77
|
this.clients.delete(clientId);
|
|
85
78
|
};
|
|
86
|
-
|
|
87
79
|
socket.addEventListener('error', onClose);
|
|
88
80
|
socket.addEventListener('close', onClose);
|
|
89
81
|
socket.addEventListener('message', event => {
|
|
90
82
|
this.processMessage(event.data.toString());
|
|
91
83
|
});
|
|
92
84
|
}
|
|
93
|
-
|
|
94
85
|
}
|
|
95
86
|
//# sourceMappingURL=WebSocketDevClientServer.js.map
|
|
@@ -1 +1 @@
|
|
|
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","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\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 {\n this.fastify.log.info({ 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\n this.fastify.log.info({ msg: 'React Native client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\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,
|
|
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","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\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 {\n this.fastify.log.info({ 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\n this.fastify.log.info({ msg: 'React Native client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\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,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;EACEC,cAAcA,CAACC,OAAe,EAAE;IAC9B,MAAM;MAAEC,IAAI;MAAE,GAAGC;IAAK,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACJ,OAAO,CAAC;IAC7C,QAAQC,IAAI;MACV,KAAK,YAAY;QACf,IAAIC,IAAI,CAACG,KAAK,KAAK,OAAO,EAAE;UAC1B,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;YAAEC,MAAM,EAAE,SAAS;YAAEC,GAAG,EAAEP,IAAI,CAACQ;UAAK,CAAC,CAAC;QAC/D,CAAC,MAAM,IAAIR,IAAI,CAACG,KAAK,KAAK,MAAM,EAAE;UAChC,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACK,IAAI,CAAC;YAAEH,MAAM,EAAE,SAAS;YAAEC,GAAG,EAAEP,IAAI,CAACQ;UAAK,CAAC,CAAC;QAC9D,CAAC,MAAM;UACL,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACM,IAAI,CAAC;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