Skip to content

Support WebSockets #1

@PatrickG

Description

@PatrickG

I think it would be nice, if this adapter would support websockets that can be handled from within a sveltekit app.
Maybe with the new filestructure, we can use routes/ws/+websocket.js files.

I guess we would need to create a vite plugin, to support websockets in dev mode.

How a +websocket.js file could look like:

// routes/example/+websocket.js
export function OPEN({ ws }: { ws: WebSocket }) {
}

export function MESSAGE({ ws, message, isBinary }: { ws: WebSocket; message: ArrayBuffer; isBinary: boolean }) {
}

export function CLOSE({ ws, code, message }: { ws: WebSocket; code: number; message: ArrayBuffer }) {
}

OR a default export of the WebSocketBehavior type

// routes/example/+websocket.js
/** @type import('uWebSocket').WebSocketBehavior */
export default {
  open(ws) {},
  message(ws, message, isBinary) {},
  close(ws, code, message) {},
};

But it would be good to have the app available in these functions as well, to publish a message. Or maybe just a publish function that is passed as parameter to these functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions