@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
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import * as prettyFormat from 'pretty-format';
|
|
2
|
-
import { WebSocketServer } from
|
|
3
|
-
/**
|
|
4
|
-
* {@link WebSocketEventsServer} configuration options.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Represents a command that connected clients can send to the {@link WebSocketEventsServer}.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Represents an event message.
|
|
11
|
-
*/
|
|
2
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
12
3
|
/**
|
|
13
4
|
* Class for creating a WebSocket server to process events and reports.
|
|
14
5
|
*
|
|
@@ -17,164 +8,155 @@ import { WebSocketServer } from "../WebSocketServer.js";
|
|
|
17
8
|
* @category Development server
|
|
18
9
|
*/
|
|
19
10
|
export class WebSocketEventsServer extends WebSocketServer {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return /^(https?:\/\/localhost|file:\/\/)/.test(origin);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
this.config = config;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Parse received command message from connected client.
|
|
44
|
-
*
|
|
45
|
-
* @param data Stringified command message to parse.
|
|
46
|
-
* @returns Parsed command or `undefined` if parsing failed.
|
|
47
|
-
*/
|
|
48
|
-
parseMessage(data) {
|
|
49
|
-
try {
|
|
50
|
-
const message = JSON.parse(data);
|
|
51
|
-
if (message.version === WebSocketEventsServer.PROTOCOL_VERSION) {
|
|
52
|
-
return message;
|
|
53
|
-
}
|
|
54
|
-
this.fastify.log.error({
|
|
55
|
-
msg: 'Received message had wrong protocol version',
|
|
56
|
-
message
|
|
57
|
-
});
|
|
58
|
-
} catch {
|
|
59
|
-
this.fastify.log.error({
|
|
60
|
-
msg: 'Failed to parse the message as JSON',
|
|
61
|
-
data
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Stringify `message` into a format that can be transported as a `string`.
|
|
69
|
-
*
|
|
70
|
-
* @param message Message to serialize.
|
|
71
|
-
* @returns String representation of a `message` or `undefined` if serialization failed.
|
|
72
|
-
*/
|
|
73
|
-
serializeMessage(message) {
|
|
74
|
-
let toSerialize = message;
|
|
75
|
-
if (message.error && message.error instanceof Error) {
|
|
76
|
-
toSerialize = {
|
|
77
|
-
...message,
|
|
78
|
-
error: prettyFormat.default(message.error, {
|
|
79
|
-
escapeString: true,
|
|
80
|
-
highlight: true,
|
|
81
|
-
maxDepth: 3,
|
|
82
|
-
min: true
|
|
83
|
-
})
|
|
84
|
-
};
|
|
85
|
-
} else if (message && message.type === 'client_log') {
|
|
86
|
-
toSerialize = {
|
|
87
|
-
...message,
|
|
88
|
-
data: message.data.map(item => typeof item === 'string' ? item : prettyFormat.default(item, {
|
|
89
|
-
escapeString: true,
|
|
90
|
-
highlight: true,
|
|
91
|
-
maxDepth: 3,
|
|
92
|
-
min: true,
|
|
93
|
-
plugins: [prettyFormat.plugins.ReactElement]
|
|
94
|
-
}))
|
|
95
|
-
};
|
|
11
|
+
/**
|
|
12
|
+
* Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
|
|
13
|
+
* Any logging information, will be passed through standard `fastify.log` API.
|
|
14
|
+
*
|
|
15
|
+
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
16
|
+
* @param config Configuration object.
|
|
17
|
+
*/
|
|
18
|
+
constructor(fastify, config) {
|
|
19
|
+
super(fastify, '/events', {
|
|
20
|
+
verifyClient: (({ origin }) => {
|
|
21
|
+
return /^(https?:\/\/localhost|file:\/\/)/.test(origin);
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
this.config = config;
|
|
25
|
+
this.clients = new Map();
|
|
26
|
+
this.nextClientId = 0;
|
|
96
27
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Parse received command message from connected client.
|
|
30
|
+
*
|
|
31
|
+
* @param data Stringified command message to parse.
|
|
32
|
+
* @returns Parsed command or `undefined` if parsing failed.
|
|
33
|
+
*/
|
|
34
|
+
parseMessage(data) {
|
|
35
|
+
try {
|
|
36
|
+
const message = JSON.parse(data);
|
|
37
|
+
if (message.version === WebSocketEventsServer.PROTOCOL_VERSION) {
|
|
38
|
+
return message;
|
|
39
|
+
}
|
|
40
|
+
this.fastify.log.error({
|
|
41
|
+
msg: 'Received message had wrong protocol version',
|
|
42
|
+
message,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
this.fastify.log.error({
|
|
47
|
+
msg: 'Failed to parse the message as JSON',
|
|
48
|
+
data,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
105
52
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Stringify `message` into a format that can be transported as a `string`.
|
|
55
|
+
*
|
|
56
|
+
* @param message Message to serialize.
|
|
57
|
+
* @returns String representation of a `message` or `undefined` if serialization failed.
|
|
58
|
+
*/
|
|
59
|
+
serializeMessage(message) {
|
|
60
|
+
let toSerialize = message;
|
|
61
|
+
if (message.error && message.error instanceof Error) {
|
|
62
|
+
toSerialize = {
|
|
63
|
+
...message,
|
|
64
|
+
error: prettyFormat.default.default(message.error, {
|
|
65
|
+
escapeString: true,
|
|
66
|
+
highlight: true,
|
|
67
|
+
maxDepth: 3,
|
|
68
|
+
min: true,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else if (message && message.type === 'client_log') {
|
|
73
|
+
toSerialize = {
|
|
74
|
+
...message,
|
|
75
|
+
data: message.data.map((item) => typeof item === 'string'
|
|
76
|
+
? item
|
|
77
|
+
: prettyFormat.default.default(item, {
|
|
78
|
+
escapeString: true,
|
|
79
|
+
highlight: true,
|
|
80
|
+
maxDepth: 3,
|
|
81
|
+
min: true,
|
|
82
|
+
plugins: [prettyFormat.plugins.ReactElement],
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return JSON.stringify(toSerialize);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.fastify.log.error({ msg: 'Failed to serialize', error });
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
116
93
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Broadcast event to all connected clients.
|
|
96
|
+
*
|
|
97
|
+
* @param event Event message to broadcast.
|
|
98
|
+
*/
|
|
99
|
+
broadcastEvent(event) {
|
|
100
|
+
if (!this.clients.size) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const serialized = this.serializeMessage(event);
|
|
104
|
+
if (!serialized) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
for (const [clientId, socket] of this.clients.entries()) {
|
|
108
|
+
try {
|
|
109
|
+
socket.send(serialized);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.fastify.log.error({
|
|
113
|
+
msg: 'Failed to send broadcast to client',
|
|
114
|
+
clientId,
|
|
115
|
+
error,
|
|
116
|
+
_skipBroadcast: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Process new client's WebSocket connection.
|
|
123
|
+
*
|
|
124
|
+
* @param socket Incoming WebSocket connection.
|
|
125
|
+
*/
|
|
126
|
+
onConnection(socket) {
|
|
127
|
+
const clientId = `client#${this.nextClientId++}`;
|
|
128
|
+
this.clients.set(clientId, socket);
|
|
129
|
+
this.fastify.log.debug({ msg: 'Events client connected', clientId });
|
|
130
|
+
const onClose = () => {
|
|
131
|
+
this.fastify.log.debug({ msg: 'Events client disconnected', clientId });
|
|
132
|
+
socket.removeAllListeners();
|
|
133
|
+
this.clients.delete(clientId);
|
|
134
|
+
};
|
|
135
|
+
socket.addEventListener('error', onClose);
|
|
136
|
+
socket.addEventListener('close', onClose);
|
|
137
|
+
socket.addEventListener('message', (event) => {
|
|
138
|
+
const message = this.parseMessage(event.data.toString());
|
|
139
|
+
if (!message) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (message.type === 'command') {
|
|
143
|
+
try {
|
|
144
|
+
this.config.webSocketMessageServer.broadcast(message.command, message.params);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
this.fastify.log.error({
|
|
148
|
+
msg: 'Failed to forward message to clients',
|
|
149
|
+
error,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.fastify.log.error({
|
|
155
|
+
msg: 'Unknown message type',
|
|
156
|
+
message,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
130
159
|
});
|
|
131
|
-
}
|
|
132
160
|
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Process new client's WebSocket connection.
|
|
137
|
-
*
|
|
138
|
-
* @param socket Incoming WebSocket connection.
|
|
139
|
-
*/
|
|
140
|
-
onConnection(socket) {
|
|
141
|
-
const clientId = `client#${this.nextClientId++}`;
|
|
142
|
-
this.clients.set(clientId, socket);
|
|
143
|
-
this.fastify.log.debug({
|
|
144
|
-
msg: 'Events client connected',
|
|
145
|
-
clientId
|
|
146
|
-
});
|
|
147
|
-
const onClose = () => {
|
|
148
|
-
this.fastify.log.debug({
|
|
149
|
-
msg: 'Events client disconnected',
|
|
150
|
-
clientId
|
|
151
|
-
});
|
|
152
|
-
socket.removeAllListeners();
|
|
153
|
-
this.clients.delete(clientId);
|
|
154
|
-
};
|
|
155
|
-
socket.addEventListener('error', onClose);
|
|
156
|
-
socket.addEventListener('close', onClose);
|
|
157
|
-
socket.addEventListener('message', event => {
|
|
158
|
-
const message = this.parseMessage(event.data.toString());
|
|
159
|
-
if (!message) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (message.type === 'command') {
|
|
163
|
-
try {
|
|
164
|
-
this.config.webSocketMessageServer.broadcast(message.command, message.params);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
this.fastify.log.error({
|
|
167
|
-
msg: 'Failed to forward message to clients',
|
|
168
|
-
error
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
this.fastify.log.error({
|
|
173
|
-
msg: 'Unknown message type',
|
|
174
|
-
message
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
161
|
}
|
|
180
|
-
|
|
162
|
+
WebSocketEventsServer.PROTOCOL_VERSION = 2;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
3
|
import type WebSocket from 'ws';
|
|
4
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
5
|
-
import type { HmrDelegate } from '../types';
|
|
4
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
5
|
+
import type { HmrDelegate } from '../types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Class for creating a WebSocket server for Hot Module Replacement.
|
|
8
8
|
*
|
|
@@ -1,89 +1,82 @@
|
|
|
1
1
|
import { URL } from 'node:url';
|
|
2
|
-
import { WebSocketServer } from
|
|
2
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
3
3
|
/**
|
|
4
4
|
* Class for creating a WebSocket server for Hot Module Replacement.
|
|
5
5
|
*
|
|
6
6
|
* @category Development server
|
|
7
7
|
*/
|
|
8
8
|
export class WebSocketHMRServer extends WebSocketServer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.delegate = delegate;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Send action to all connected HMR clients.
|
|
26
|
-
*
|
|
27
|
-
* @param event Event to send to the clients.
|
|
28
|
-
* @param platform Platform of clients to send the event to.
|
|
29
|
-
* @param clientIds Ids of clients who should receive the event.
|
|
30
|
-
*/
|
|
31
|
-
send(event, platform, clientIds) {
|
|
32
|
-
const data = typeof event === 'string' ? event : JSON.stringify(event);
|
|
33
|
-
for (const [key, socket] of this.clients) {
|
|
34
|
-
if (key.platform !== platform || !(clientIds ?? [key.clientId]).includes(key.clientId)) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
socket.send(data);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
this.fastify.log.error({
|
|
41
|
-
msg: 'Cannot send action to client',
|
|
42
|
-
event,
|
|
43
|
-
error,
|
|
44
|
-
...key
|
|
45
|
-
});
|
|
46
|
-
}
|
|
9
|
+
/**
|
|
10
|
+
* Create new instance of WebSocketHMRServer 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
|
+
* @param delegate HMR delegate instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor(fastify, delegate) {
|
|
17
|
+
super(fastify, delegate.getUriPath());
|
|
18
|
+
this.delegate = delegate;
|
|
19
|
+
this.clients = new Map();
|
|
20
|
+
this.nextClientId = 0;
|
|
47
21
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Send action to all connected HMR clients.
|
|
24
|
+
*
|
|
25
|
+
* @param event Event to send to the clients.
|
|
26
|
+
* @param platform Platform of clients to send the event to.
|
|
27
|
+
* @param clientIds Ids of clients who should receive the event.
|
|
28
|
+
*/
|
|
29
|
+
send(event, platform, clientIds) {
|
|
30
|
+
const data = typeof event === 'string' ? event : JSON.stringify(event);
|
|
31
|
+
for (const [key, socket] of this.clients) {
|
|
32
|
+
if (key.platform !== platform ||
|
|
33
|
+
!(clientIds ?? [key.clientId]).includes(key.clientId)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
socket.send(data);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
this.fastify.log.error({
|
|
41
|
+
msg: 'Cannot send action to client',
|
|
42
|
+
event,
|
|
43
|
+
error,
|
|
44
|
+
...key,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Process new WebSocket connection from HMR client.
|
|
51
|
+
*
|
|
52
|
+
* @param socket Incoming HMR client's WebSocket connection.
|
|
53
|
+
*/
|
|
54
|
+
onConnection(socket, request) {
|
|
55
|
+
const { searchParams } = new URL(request.url || '', 'http://localhost');
|
|
56
|
+
const platform = searchParams.get('platform');
|
|
57
|
+
if (!platform) {
|
|
58
|
+
this.fastify.log.debug({
|
|
59
|
+
msg: 'HMR connection disconnected - missing platform',
|
|
60
|
+
});
|
|
61
|
+
socket.close();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const clientId = `client#${this.nextClientId++}`;
|
|
65
|
+
const client = {
|
|
66
|
+
clientId,
|
|
67
|
+
platform,
|
|
68
|
+
};
|
|
69
|
+
this.clients.set(client, socket);
|
|
70
|
+
this.fastify.log.debug({ msg: 'HMR client connected', ...client });
|
|
71
|
+
const onClose = () => {
|
|
72
|
+
this.fastify.log.debug({
|
|
73
|
+
msg: 'HMR client disconnected',
|
|
74
|
+
...client,
|
|
75
|
+
});
|
|
76
|
+
this.clients.delete(client);
|
|
77
|
+
};
|
|
78
|
+
socket.addEventListener('error', onClose);
|
|
79
|
+
socket.addEventListener('close', onClose);
|
|
80
|
+
this.delegate.onClientConnected(platform, clientId);
|
|
66
81
|
}
|
|
67
|
-
const clientId = `client#${this.nextClientId++}`;
|
|
68
|
-
const client = {
|
|
69
|
-
clientId,
|
|
70
|
-
platform
|
|
71
|
-
};
|
|
72
|
-
this.clients.set(client, socket);
|
|
73
|
-
this.fastify.log.debug({
|
|
74
|
-
msg: 'HMR client connected',
|
|
75
|
-
...client
|
|
76
|
-
});
|
|
77
|
-
const onClose = () => {
|
|
78
|
-
this.fastify.log.debug({
|
|
79
|
-
msg: 'HMR client disconnected',
|
|
80
|
-
...client
|
|
81
|
-
});
|
|
82
|
-
this.clients.delete(client);
|
|
83
|
-
};
|
|
84
|
-
socket.addEventListener('error', onClose);
|
|
85
|
-
socket.addEventListener('close', onClose);
|
|
86
|
-
this.delegate.onClientConnected(platform, clientId);
|
|
87
|
-
}
|
|
88
82
|
}
|
|
89
|
-
//# sourceMappingURL=WebSocketHMRServer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
3
|
import type WebSocket from 'ws';
|
|
4
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
4
|
+
import { WebSocketServer } from '../WebSocketServer.js';
|
|
5
5
|
/**
|
|
6
6
|
* Holds {@link ReactNativeMessage} `id` data.
|
|
7
7
|
*/
|