diff --git a/websocket/api/api.script_api b/websocket/api/api.script_api index cb9572b..c5f1337 100644 --- a/websocket/api/api.script_api +++ b/websocket/api/api.script_api @@ -23,7 +23,7 @@ - name: protocol type: string - desc: the protocol to use (e.g. 'chat'). (Default is 'binary') + desc: the protocol to use (e.g. 'chat'). If not set, no `Sec-WebSocket-Protocol` header is sent. - name: headers type: string diff --git a/websocket/src/websocket.cpp b/websocket/src/websocket.cpp index 6df1c9d..41e5cf4 100644 --- a/websocket/src/websocket.cpp +++ b/websocket/src/websocket.cpp @@ -712,12 +712,10 @@ static dmExtension::Result OnUpdate(dmExtension::Params* params) #if defined(__EMSCRIPTEN__) conn->m_SSLSocket = dmSSLSocket::INVALID_SOCKET_HANDLE; - if (conn->m_Protocol) { - EM_ASM({ - // https://emscripten.org/docs/porting/networking.html#emulated-posix-tcp-sockets-over-websockets - Module["websocket"]["subprotocol"] = UTF8ToString($0); - }, conn->m_Protocol); - } + EM_ASM({ + // https://emscripten.org/docs/porting/networking.html#emulated-posix-tcp-sockets-over-websockets + Module["websocket"]["subprotocol"] = $0 ? UTF8ToString($0) : null; + }, conn->m_Protocol); char uri_buffer[dmURI::MAX_URI_LEN]; const char* uri;