Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket::path() returns nullopt when state is Connecting #1224

Open
murat-dogan opened this issue Jul 5, 2024 · 2 comments
Open

WebSocket::path() returns nullopt when state is Connecting #1224

murat-dogan opened this issue Jul 5, 2024 · 2 comments

Comments

@murat-dogan
Copy link
Contributor

I am converting ws to native WebSocket functions.
Sometimes app can not read path.

I added a workaround for now here
https://github.com/murat-dogan/node-datachannel/blob/c311c111bdd1b3c20d056f6f46a7c3c12610f8ce/examples/client-server/signaling-server.js#L11

The problem is related to this line

return state != State::Connecting && handshake ? make_optional(handshake->path()) : nullopt;

When onClient callback is called, it is still in Connecting state (handshake->path() is valid though)

Can we remove this condition, or there are some other reasons?

@paullouisageneau
Copy link
Owner

The onClient() callback is triggered early, as soon as the client connects with TCP. This allows the server to react on the remote address, for instance. The path is available only after handshake is finished, which happens in parallel and probably won't be finished when onClient() is scheduled. To be sure the path is available, you should read it in the onOpen() callback, which is triggered after a successful handshake.

@murat-dogan
Copy link
Contributor Author

With ws module I can read it on-connection event
https://github.com/murat-dogan/node-datachannel/blob/63ec3215063931aae772f2acfa2c2199bfeca2b3/examples/client-server/signaling-server.js#L8

I can move it to onOpen no problem, but it will be good to have the same behaviour for general use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants