emscripten-core / emscripten-core/emscripten
Use globalThis.WebSocket in Node.js before of require('ws')
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
We can use the [Native WebSocket Client in Node.js](https://nodejs.org/learn/getting-started/websocket#native-websocket-client-in-nodejs) on Node >= 21 instsead of hardcoding `require('ws')`
https://github.com/emscripten-core/emscripten/blob/6ea9c28c38cdd40c1032fa04400c9d16230ee180/src/lib/libsockfs.js#L217-L221
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
- https://github.com/r-wasm/webr/pull/562
- https://github.com/r-wasm/webr/pull/576
- https://github.com/jeroen/webr/pull/1
Contributor guide
Assessment
This issue has not been assessed yet.