emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.88k stars 3.32k forks source link

websocket protocols #12745

Open JCash opened 4 years ago

JCash commented 4 years ago

Hi!

Forgive me if this is a duplicate, but I couldn't find any info about this in the issues/documentation.

I have two possibly related issues with how websockets are setup.

  1. Sec-WebSocket-Protocol is always sent.

For some reason, if this header is sent, Google Chrome expects the identical (!?) result back.

VM127:1 WebSocket connection to 'ws://echo.websocket.org/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

This isn't an issue in Firefox.

Currently, the workaround is to "remove" the subprotocol altogether:

EM_ASM({
    Module["websocket"]["subprotocol"] = $0 ? UTF8ToString($0) : null;
}, conn->m_Protocol);

It works, but it feels a bit hacky, and it isn't documented anywhere. Or perhaps there is, but I missed it? Is there a better way to do this?

  1. Even if subprotocol is text, websockets still send using binary.

Inspecting the packets sent, it sends them using binary format (using control byte 0x82 as opposed to 0x81) Also, I'm guessing the user might want to send both text and binary messages over the websocket. Any ideas on how to achieve this?

JCash commented 3 years ago

Noone has any insight?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

gmluo2 commented 2 years ago

Thanks for the comment. Same problem happens to me when using ffmpeg.wasm. Chrome requires the handshake response from server having same "Sec-WebSocket-Protocol" in the header as the request. Need to add the "binary" protocol into handshake response header.