Skip to content

Conversation

@nksaraf
Copy link

@nksaraf nksaraf commented Sep 24, 2023

depends on unjs/listhen#128

adds websocket support by giving a few helpers, highlighted here. This can be added at the top of an event handler, and its a web socket serevr ready to do with all handling logic in your hand.

if (isWebSocketEvent(event)) {
      const wsEvent = toWebSocketEvent(event);
      if (wsEvent.type === "connection") {
        wsEvent.connection.send("pong");
      } else if (wsEvent.type === "message") {
        console.log("got", new TextDecoder().decode(wsEvent.message));
      }
    }
    if (isWebSocketUpgradeRequest(event)) {
      return upgradeWebSocket(event);
    }

@nksaraf nksaraf changed the title add websocket support feat: add websocket support utils, and app handling Sep 24, 2023
@byteab
Copy link

byteab commented Dec 31, 2023

@pi0 is there any chance to merge this PR

@pi0
Copy link
Member

pi0 commented Jan 25, 2024

Thanks for PR. ws is a Node.js dependency and we aim for cross platfom/runtime. Closing for triage.

@pi0 pi0 closed this Jan 25, 2024
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

Successfully merging this pull request may close these issues.

3 participants