Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for dynamically resolving the WebSocket URL via a function and customizing the WebSocket constructor at runtime, updating both the implementation in libsockfs.js and the documentation. The review comments point out a critical issue where runtime changes to Module['websocket'] may not be detected if it was not defined at startup due to decoupling from SOCKFS.websocketArgs. It is recommended to use Module['websocket'] || SOCKFS.websocketArgs to correctly resolve these properties at runtime.
ading2210
force-pushed
the
feature-websocket-contructor
branch
from
November 11, 2026 01:19
ae47e50 to
0c33c0f
Compare
ading2210
force-pushed
the
feature-websocket-contructor
branch
from
November 11, 2026 01:21
0c33c0f to
0aab669
Compare
Author
|
All the Gemini comments have been resolved. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds new features to the POSIX socket emulation over WebSockets. This is a very small change that allows for a great deal of flexibility in Emscripten's networking.
It adds the ability to change the WebSocket constructor to any custom class/function, by changing
Module['websocket']['constructor'];. For example:Or if we want to control the arguments passed into the constructor:
This lets us change the underlying network transport for the socket to whatever we want, so long as a WebSocket-compatible class with the same API surface is used. For instance, you could create a wrapper for WebTransport data channels, WebRTC data channels, or direct sockets.
This PR also adds the ability to make
Module['websocket']['url']a function rather than a string, which maps the hostname and port to a URL. For instance, you could use:In this example, it would cause every TCP socket opened to create a new WebSocket with the hostname and port in the URL path.
I'm making this change because I've encountered a lot of uses cases where I'd want to write a custom network transport for Emscripten programs. I'd usually have to intercept the global
window.WebSocketobject or patch Emscripten's emitted JS code. I could avoid all of that if the features described in this PR are merged.