Deno

Manually integrate crossws with Deno.
You can use serve function from crossws/server to automatically integrate crossws with Deno!

To manually 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" } },
  );
});
See test/fixture/deno.ts for demo and src/adapters/deno.ts for implementation.

Idle timeout

The shared idleTimeout option (in seconds) closes connections that die silently (half-open sockets). It maps to Deno's native Deno.upgradeWebSocket idle timeout, which auto-sends keepalive pings. Defaults to 30; pass 0 to disable.

const ws = crossws({ idleTimeout: 60, hooks: { message: console.log } });