We can use the Native WebSocket Client in Node.js on Node >= 21 instsead of hardcoding require('ws')
|
#if ENVIRONMENT_MAY_BE_NODE |
|
if (ENVIRONMENT_IS_NODE) { |
|
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('ws')); |
|
} else |
|
#endif // ENVIRONMENT_MAY_BE_NODE |
An additional reason is that applications may use a proxy for globalThis.WebSocket to proxy webSocket communication through the main thread. However this gets ignored when emscripten hardcodes require('ws').
See
We can use the Native WebSocket Client in Node.js on Node >= 21 instsead of hardcoding
require('ws')emscripten/src/lib/libsockfs.js
Lines 217 to 221 in 6ea9c28
An additional reason is that applications may use a proxy for
globalThis.WebSocketto proxy webSocket communication through the main thread. However this gets ignored when emscripten hardcodesrequire('ws').See