emscripten-core / emscripten-core/emscripten

websocket protocols

Open
#12,745 6 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

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:

```c++
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?

2. 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?

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.