Skip to content

EmscriptenWebSocketCloseEvent->code and wasClean are incorrect and messed #22499

@yanxia97

Description

@yanxia97

Please include the following in your bug report:

Version of emscripten/emsdk:
emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.57 (1df9c19)
clang version 19.0.0git (https:/github.com/llvm/llvm-project ccdebbae4d77d3efc236af92c22941de5d437e01)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/yanxia/Desktop/emsdk/upstream/bin
Build config: +assertions

I try to get the code and reason in the close callback. Here is my code example.

EM_BOOL EmscriptenConnection::OnWebSocketClose(int eventType, const EmscriptenWebSocketCloseEvent *websocketEvent,
                                               void *userData) {
  auto connection = static_cast<EmscriptenConnection *>(userData);

  unsigned short code = websocketEvent->code;
  auto reason = websocketEvent->reason;

  connection->connecting_ = false;
  connection->connected_ = false;

  if (connection->on_close_callback_) {
    connection->on_close_callback_(connection, code, reason);
  }

  return EM_TRUE;
}

The problem is that the code the server sent is not the code I recieved. And I find in the line 220 of file library_websocket.js from the main branch right now, there is a typo.

      {{{ makeSetValue('eventPtr', C_STRUCTS.EmscriptenWebSocketCloseEvent.wasClean, 'e.code', 'i16') }}},

issue2024-09-04 15 25 35

As a result, EmscriptenWebSocketCloseEvent->code is incorrect and EmscriptenWebSocketCloseEvent->wasClean somehow works as the code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions