emscripten-core / emscripten-core/emscripten

Use globalThis.WebSocket in Node.js before of require('ws')

Open
#26,676 4 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.