mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-09 12:27:45 +00:00
1.0 KiB
1.0 KiB
icon
| icon |
|---|
| teenyicons:deno-solid |
Deno
Integrate crossws with Deno.
To integrate crossws with your Deno server, you need to check for the upgrade header and then call handleUpgrade method from the adapter passing the incoming request object. The returned value is the server upgrade response.
import crossws from "crossws/adapters/deno";
const ws = crossws({
hooks: {
message: console.log,
},
});
Deno.serve({ port: 3000 }, (request, info) => {
if (request.headers.get("upgrade") === "websocket") {
return ws.handleUpgrade(request, info);
}
return new Response(
`<script>new WebSocket("ws://localhost:3000").addEventListener("open", (e) => e.target.send("Hello from client!"));</script>`,
{ headers: { "content-type": "text/html" } },
);
});
Adapter Hooks
deno:open (peer)deno:message (peer, event)deno:close (peer)deno:error (peer, error)
::read-more
See test/fixture/deno.ts for demo and src/adapters/deno.ts for implementation.
::