@callstack/repack-dev-server 5.0.0-rc.2 → 5.0.0-rc.4
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 -123
- 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 -19
- 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 -8
- package/dist/plugins/wss/wssPlugin.js +37 -42
- package/dist/types.d.ts +6 -6
- package/dist/types.js +8 -18
- package/package.json +4 -8
- package/CHANGELOG.md +0 -160
- 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/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
|
@@ -9,49 +9,44 @@
|
|
|
9
9
|
* @category Development server
|
|
10
10
|
*/
|
|
11
11
|
export class WebSocketRouter {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.
|
|
14
|
+
* Any logging information, will be passed through standard `fastify.log` API.
|
|
15
|
+
*
|
|
16
|
+
* @param fastify Fastify instance to attach the WebSocket router to.
|
|
17
|
+
*/
|
|
18
|
+
constructor(fastify) {
|
|
19
|
+
this.fastify = fastify;
|
|
20
|
+
/** The list of all register WebSocket servers. */
|
|
21
|
+
this.servers = [];
|
|
22
|
+
this.fastify.server.on('upgrade', (request, socket, head) => {
|
|
23
|
+
const { pathname } = new URL(request.url || '', 'http://localhost');
|
|
24
|
+
let matched = false;
|
|
25
|
+
for (const server of this.servers) {
|
|
26
|
+
if (server.shouldUpgrade(pathname)) {
|
|
27
|
+
matched = true;
|
|
28
|
+
server.upgrade(request, socket, head);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!matched) {
|
|
33
|
+
this.fastify.log.debug({
|
|
34
|
+
msg: 'Destroying socket connection as no server was matched',
|
|
35
|
+
pathname,
|
|
36
|
+
});
|
|
37
|
+
socket.destroy();
|
|
38
|
+
}
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
registerServer(server) {
|
|
53
|
-
this.servers.push(server);
|
|
54
|
-
return server;
|
|
55
|
-
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register a new {@link WebSocketServer}. New connection will now
|
|
43
|
+
* check if the given server will accept them and forward them.
|
|
44
|
+
*
|
|
45
|
+
* @param server WebSocket server to register.
|
|
46
|
+
* @returns The same instance of the WebSocket server after it's been registered.
|
|
47
|
+
*/
|
|
48
|
+
registerServer(server) {
|
|
49
|
+
this.servers.push(server);
|
|
50
|
+
return server;
|
|
51
|
+
}
|
|
56
52
|
}
|
|
57
|
-
//# sourceMappingURL=WebSocketRouter.js.map
|
|
@@ -2,7 +2,7 @@ import type { IncomingMessage } from 'node:http';
|
|
|
2
2
|
import type { Socket } from 'node:net';
|
|
3
3
|
import type { FastifyInstance } from 'fastify';
|
|
4
4
|
import { type ServerOptions, type WebSocket, WebSocketServer as WebSocketServerImpl } from 'ws';
|
|
5
|
-
import type { WebSocketServerInterface } from './types';
|
|
5
|
+
import type { WebSocketServerInterface } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Abstract class for providing common logic (eg routing) for all WebSocket servers.
|
|
8
8
|
*
|
|
@@ -1,45 +1,30 @@
|
|
|
1
|
-
import { WebSocketServer as WebSocketServerImpl } from 'ws';
|
|
1
|
+
import { WebSocketServer as WebSocketServerImpl, } from 'ws';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract class for providing common logic (eg routing) for all WebSocket servers.
|
|
4
4
|
*
|
|
5
5
|
* @category Development server
|
|
6
6
|
*/
|
|
7
7
|
export class WebSocketServer {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return this.paths.includes(pathname);
|
|
31
|
-
}
|
|
32
|
-
upgrade(request, socket, head) {
|
|
33
|
-
this.server.handleUpgrade(request, socket, head, webSocket => {
|
|
34
|
-
this.server.emit('connection', webSocket, request);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Process incoming WebSocket connection.
|
|
40
|
-
*
|
|
41
|
-
* @param socket Incoming WebSocket connection.
|
|
42
|
-
* @param request Upgrade request for the connection.
|
|
43
|
-
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create a new instance of the WebSocketServer.
|
|
10
|
+
* Any logging information, will be passed through standard `fastify.log` API.
|
|
11
|
+
*
|
|
12
|
+
* @param fastify Fastify instance to which the WebSocket will be attached to.
|
|
13
|
+
* @param path Path on which this WebSocketServer will be accepting connections.
|
|
14
|
+
* @param wssOptions WebSocket Server options.
|
|
15
|
+
*/
|
|
16
|
+
constructor(fastify, path, wssOptions = {}) {
|
|
17
|
+
this.fastify = fastify;
|
|
18
|
+
this.server = new WebSocketServerImpl({ noServer: true, ...wssOptions });
|
|
19
|
+
this.server.on('connection', this.onConnection.bind(this));
|
|
20
|
+
this.paths = Array.isArray(path) ? path : [path];
|
|
21
|
+
}
|
|
22
|
+
shouldUpgrade(pathname) {
|
|
23
|
+
return this.paths.includes(pathname);
|
|
24
|
+
}
|
|
25
|
+
upgrade(request, socket, head) {
|
|
26
|
+
this.server.handleUpgrade(request, socket, head, (webSocket) => {
|
|
27
|
+
this.server.emit('connection', webSocket, request);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
44
30
|
}
|
|
45
|
-
//# sourceMappingURL=WebSocketServer.js.map
|
|
@@ -2,7 +2,7 @@ import type { IncomingMessage } from 'node:http';
|
|
|
2
2
|
import type { Socket } from 'node:net';
|
|
3
3
|
import type { FastifyInstance } from 'fastify';
|
|
4
4
|
import type { WebSocketServer } from 'ws';
|
|
5
|
-
import type { WebSocketServerInterface } from './types';
|
|
5
|
+
import type { WebSocketServerInterface } from './types.js';
|
|
6
6
|
export declare class WebSocketServerAdapter implements WebSocketServerInterface {
|
|
7
7
|
private fastify;
|
|
8
8
|
private path;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
export class WebSocketServerAdapter {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
constructor(fastify, path, server) {
|
|
3
|
+
this.fastify = fastify;
|
|
4
|
+
this.path = path;
|
|
5
|
+
this.server = server;
|
|
6
|
+
}
|
|
7
|
+
shouldUpgrade(pathname) {
|
|
8
|
+
if (!this.server) {
|
|
9
|
+
this.fastify.log.warn({ msg: `No handler active for ${this.path}` });
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return this.path === pathname;
|
|
13
|
+
}
|
|
14
|
+
upgrade(request, socket, head) {
|
|
15
|
+
this.server?.handleUpgrade(request, socket, head, (webSocket) => {
|
|
16
|
+
this.server?.emit('connection', webSocket, request);
|
|
17
|
+
});
|
|
13
18
|
}
|
|
14
|
-
return this.path === pathname;
|
|
15
|
-
}
|
|
16
|
-
upgrade(request, socket, head) {
|
|
17
|
-
this.server?.handleUpgrade(request, socket, head, webSocket => {
|
|
18
|
-
this.server?.emit('connection', webSocket, request);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
19
|
}
|
|
22
|
-
//# sourceMappingURL=WebSocketServerAdapter.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default } from './wssPlugin';
|
|
2
|
-
export * from './WebSocketServer';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export { default } from './wssPlugin.js';
|
|
2
|
+
export * from './WebSocketServer.js';
|
|
3
|
+
export * from './types.js';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './wssPlugin.js';
|
|
2
|
+
export * from './WebSocketServer.js';
|
|
3
|
+
export * from './types.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
2
|
import type WebSocket from 'ws';
|
|
3
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
3
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Class for creating a WebSocket server for API clients.
|
|
6
6
|
* Useful to listening for compilation events and new logs.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebSocketServer } from
|
|
1
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
2
2
|
/**
|
|
3
3
|
* Class for creating a WebSocket server for API clients.
|
|
4
4
|
* Useful to listening for compilation events and new logs.
|
|
@@ -6,57 +6,51 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
6
6
|
* @category Development server
|
|
7
7
|
*/
|
|
8
8
|
export class WebSocketApiServer extends WebSocketServer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
|
|
11
|
+
* Any logging information, will be passed through standard `fastify.log` API.
|
|
12
|
+
*
|
|
13
|
+
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
14
|
+
*/
|
|
15
|
+
constructor(fastify) {
|
|
16
|
+
super(fastify, '/api');
|
|
17
|
+
this.clients = new Map();
|
|
18
|
+
this.nextClientId = 0;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Send message to all connected API clients.
|
|
22
|
+
*
|
|
23
|
+
* @param event Event string or object to send.
|
|
24
|
+
*/
|
|
25
|
+
send(event) {
|
|
26
|
+
const data = typeof event === 'string' ? event : JSON.stringify(event);
|
|
27
|
+
for (const [, socket] of this.clients.entries()) {
|
|
28
|
+
try {
|
|
29
|
+
socket.send(data);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// NOOP
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Process new WebSocket connection from client application.
|
|
38
|
+
*
|
|
39
|
+
* @param socket Incoming client's WebSocket connection.
|
|
40
|
+
*/
|
|
41
|
+
onConnection(socket) {
|
|
42
|
+
const clientId = `client#${this.nextClientId++}`;
|
|
43
|
+
this.clients.set(clientId, socket);
|
|
44
|
+
this.fastify.log.debug({ msg: 'API client connected', clientId });
|
|
45
|
+
this.clients.set(clientId, socket);
|
|
46
|
+
const onClose = () => {
|
|
47
|
+
this.fastify.log.debug({
|
|
48
|
+
msg: 'API client disconnected',
|
|
49
|
+
clientId,
|
|
50
|
+
});
|
|
51
|
+
this.clients.delete(clientId);
|
|
52
|
+
};
|
|
53
|
+
socket.addEventListener('error', onClose);
|
|
54
|
+
socket.addEventListener('close', onClose);
|
|
35
55
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Process new WebSocket connection from client application.
|
|
40
|
-
*
|
|
41
|
-
* @param socket Incoming client's WebSocket connection.
|
|
42
|
-
*/
|
|
43
|
-
onConnection(socket) {
|
|
44
|
-
const clientId = `client#${this.nextClientId++}`;
|
|
45
|
-
this.clients.set(clientId, socket);
|
|
46
|
-
this.fastify.log.debug({
|
|
47
|
-
msg: 'API client connected',
|
|
48
|
-
clientId
|
|
49
|
-
});
|
|
50
|
-
this.clients.set(clientId, socket);
|
|
51
|
-
const onClose = () => {
|
|
52
|
-
this.fastify.log.debug({
|
|
53
|
-
msg: 'API client disconnected',
|
|
54
|
-
clientId
|
|
55
|
-
});
|
|
56
|
-
this.clients.delete(clientId);
|
|
57
|
-
};
|
|
58
|
-
socket.addEventListener('error', onClose);
|
|
59
|
-
socket.addEventListener('close', onClose);
|
|
60
|
-
}
|
|
61
56
|
}
|
|
62
|
-
//# sourceMappingURL=WebSocketApiServer.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
2
|
import type WebSocket from 'ws';
|
|
3
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
3
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Class for creating a WebSocket server for communication with React Native clients.
|
|
6
6
|
* All client logs - logs from React Native application - are processed here.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebSocketServer } from
|
|
1
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
2
2
|
/**
|
|
3
3
|
* Class for creating a WebSocket server for communication with React Native clients.
|
|
4
4
|
* All client logs - logs from React Native application - are processed here.
|
|
@@ -6,86 +6,64 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
6
6
|
* @category Development server
|
|
7
7
|
*/
|
|
8
8
|
export class WebSocketDevClientServer extends WebSocketServer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.fastify.log.info({
|
|
46
|
-
issuer: 'Console',
|
|
47
|
-
msg: body.data
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
// body.level === 'debug' || body.level === 'trace'
|
|
51
|
-
this.fastify.log.debug({
|
|
52
|
-
issuer: 'Console',
|
|
53
|
-
msg: body.data
|
|
54
|
-
});
|
|
9
|
+
/**
|
|
10
|
+
* Create new instance of WebSocketDevClientServer and attach it to the given Fastify instance.
|
|
11
|
+
* Any logging information, will be passed through standard `fastify.log` API.
|
|
12
|
+
*
|
|
13
|
+
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
14
|
+
*/
|
|
15
|
+
constructor(fastify) {
|
|
16
|
+
super(fastify, '/__client');
|
|
17
|
+
this.clients = new Map();
|
|
18
|
+
this.nextClientId = 0;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Process client message.
|
|
22
|
+
*
|
|
23
|
+
* @param message Stringified client message.
|
|
24
|
+
*/
|
|
25
|
+
processMessage(message) {
|
|
26
|
+
const { type, ...body } = JSON.parse(message);
|
|
27
|
+
switch (type) {
|
|
28
|
+
case 'client-log':
|
|
29
|
+
if (body.level === 'error') {
|
|
30
|
+
this.fastify.log.error({ issuer: 'Console', msg: body.data });
|
|
31
|
+
}
|
|
32
|
+
else if (body.level === 'warn') {
|
|
33
|
+
this.fastify.log.warn({ issuer: 'Console', msg: body.data });
|
|
34
|
+
}
|
|
35
|
+
else if (body.level === 'info' || body.level === 'log') {
|
|
36
|
+
this.fastify.log.info({ issuer: 'Console', msg: body.data });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// body.level === 'debug' || body.level === 'trace'
|
|
40
|
+
this.fastify.log.debug({ issuer: 'Console', msg: body.data });
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
this.fastify.log.warn({ msg: 'Unknown client message', message });
|
|
55
45
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Process new WebSocket connection from client application.
|
|
49
|
+
*
|
|
50
|
+
* @param socket Incoming client's WebSocket connection.
|
|
51
|
+
*/
|
|
52
|
+
onConnection(socket) {
|
|
53
|
+
const clientId = `client#${this.nextClientId++}`;
|
|
54
|
+
this.clients.set(clientId, socket);
|
|
55
|
+
this.fastify.log.debug({ msg: 'React Native client connected', clientId });
|
|
56
|
+
const onClose = () => {
|
|
57
|
+
this.fastify.log.debug({
|
|
58
|
+
msg: 'React Native client disconnected',
|
|
59
|
+
clientId,
|
|
60
|
+
});
|
|
61
|
+
this.clients.delete(clientId);
|
|
62
|
+
};
|
|
63
|
+
socket.addEventListener('error', onClose);
|
|
64
|
+
socket.addEventListener('close', onClose);
|
|
65
|
+
socket.addEventListener('message', (event) => {
|
|
66
|
+
this.processMessage(event.data.toString());
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Process new WebSocket connection from client application.
|
|
67
|
-
*
|
|
68
|
-
* @param socket Incoming client's WebSocket connection.
|
|
69
|
-
*/
|
|
70
|
-
onConnection(socket) {
|
|
71
|
-
const clientId = `client#${this.nextClientId++}`;
|
|
72
|
-
this.clients.set(clientId, socket);
|
|
73
|
-
this.fastify.log.debug({
|
|
74
|
-
msg: 'React Native client connected',
|
|
75
|
-
clientId
|
|
76
|
-
});
|
|
77
|
-
const onClose = () => {
|
|
78
|
-
this.fastify.log.debug({
|
|
79
|
-
msg: 'React Native client disconnected',
|
|
80
|
-
clientId
|
|
81
|
-
});
|
|
82
|
-
this.clients.delete(clientId);
|
|
83
|
-
};
|
|
84
|
-
socket.addEventListener('error', onClose);
|
|
85
|
-
socket.addEventListener('close', onClose);
|
|
86
|
-
socket.addEventListener('message', event => {
|
|
87
|
-
this.processMessage(event.data.toString());
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
69
|
}
|
|
91
|
-
//# sourceMappingURL=WebSocketDevClientServer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
2
|
import type WebSocket from 'ws';
|
|
3
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
4
|
-
import type { WebSocketMessageServer } from './WebSocketMessageServer';
|
|
3
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
4
|
+
import type { WebSocketMessageServer } from './WebSocketMessageServer.js';
|
|
5
5
|
/**
|
|
6
6
|
* {@link WebSocketEventsServer} configuration options.
|
|
7
7
|
*/
|