mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 04:23:02 +00:00
17 lines
2.3 KiB
JSON
17 lines
2.3 KiB
JSON
{
|
|
"id": "34552a44dcf700c6ebb11a0a",
|
|
"source": "solid:signals",
|
|
"type": "github-document",
|
|
"title": "websocket",
|
|
"content": "---\ntitle: WebSocket endpoint\nuse_cases: \u003e-\n real-time updates, chat applications, live notifications, multiplayer games,\n collaborative editing, streaming data\ntags:\n - websocket\n - real-time\n - streaming\n - experimental\n - server\n - events\nversion: '1.0'\ndescription: \u003e-\n Set up WebSocket endpoints in SolidStart for real-time bidirectional\n communication. Handle connections, messages, and events.\n---\n\nWebSocket endpoint may be included by passing the ws handler file you specify in your start config.\nNote that this feature is [experimental on the Nitro server](https://nitro.build/guide/websocket#opt-in-to-the-experimental-feature) and its config may change in future releases of SolidStart. Use it with caution.\n\n```ts title=\"./app.config.ts\"\nimport { defineConfig } from \"@solidjs/start/config\";\n\nexport default defineConfig({\n\tserver: {\n\t\texperimental: {\n\t\t\twebsocket: true,\n\t\t},\n\t},\n}).addRouter({\n\tname: \"ws\",\n\ttype: \"http\",\n\thandler: \"./src/ws.ts\",\n\ttarget: \"server\",\n\tbase: \"/ws\",\n});\n```\n\nInside the ws file, you can export an eventHandler function to manage WebSocket connections and events:\n\n```tsx title=\"./src/ws.ts\"\nimport { eventHandler } from \"vinxi/http\";\n\nexport default eventHandler({\n handler() {},\n websocket: {\n async open(peer) {\n console.log(\"open\", peer.id, peer.url);\n },\n async message(peer, msg) {\n const message = msg.text();\n console.log(\"msg\", peer.id, peer.url, message);\n },\n async close(peer, details) {\n console.log(\"close\", peer.id, peer.url);\n },\n async error(peer, error) {\n console.log(\"error\", peer.id, peer.url, error);\n },\n },\n});\n```",
|
|
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/solid-start/advanced/websocket.mdx",
|
|
"metadata": {
|
|
"path": "src/routes/solid-start/advanced/websocket.mdx",
|
|
"repo": "solidjs/solid-docs",
|
|
"repo_url": "https://github.com/solidjs/solid-docs.git",
|
|
"size": 1645,
|
|
"source_type": "github"
|
|
},
|
|
"hash": "3145c3796b65a769d82378a4be439b6316a7de041452384e5e0984e932d05f1d",
|
|
"timestamp": "2026-02-23T11:43:00.193714995+01:00"
|
|
} |