{"id":15198263,"url":"https://github.com/socketio/socket.io-deno","last_synced_at":"2025-04-05T16:04:21.097Z","repository":{"id":59111960,"uuid":"535454405","full_name":"socketio/socket.io-deno","owner":"socketio","description":"Socket.IO server for Deno","archived":false,"fork":false,"pushed_at":"2025-01-09T07:38:31.000Z","size":177,"stargazers_count":120,"open_issues_count":10,"forks_count":16,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-30T10:34:11.870Z","etag":null,"topics":["deno","javascript","socket-io","typescript","websocket"],"latest_commit_sha":null,"homepage":"https://deno.land/x/socket_io","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/socketio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-11T23:43:47.000Z","updated_at":"2025-03-27T17:59:37.000Z","dependencies_parsed_at":"2024-04-16T07:39:47.741Z","dependency_job_id":"a839bc56-120c-4532-8b8b-e74c816d572a","html_url":"https://github.com/socketio/socket.io-deno","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":"0.040000000000000036","last_synced_commit":"0b0616ce25d9396fe987ec43ec766a36c84984d3"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-deno","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-deno/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-deno/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-deno/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketio","download_url":"https://codeload.github.com/socketio/socket.io-deno/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325693,"owners_count":20920714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","javascript","socket-io","typescript","websocket"],"created_at":"2024-09-28T01:01:35.542Z","updated_at":"2025-04-05T16:04:21.067Z","avatar_url":"https://github.com/socketio.png","language":"TypeScript","readme":"# Socket.IO server for Deno\n\nAn implementation of the Socket.IO protocol for Deno.\n\nTable of content:\n\n- [Usage](#usage)\n  - [With oak](#with-oak)\n- [Options](#options)\n  - [`path`](#path)\n  - [`connectTimeout`](#connecttimeout)\n  - [`pingTimeout`](#pingtimeout)\n  - [`pingInterval`](#pinginterval)\n  - [`upgradeTimeout`](#upgradetimeout)\n  - [`maxHttpBufferSize`](#maxhttpbuffersize)\n  - [`allowRequest`](#allowrequest)\n  - [`cors`](#cors)\n  - [`editHandshakeHeaders`](#edithandshakeheaders)\n  - [`editResponseHeaders`](#editresponseheaders)\n- [Logs](#logs)\n- [Adapters](#adapters)\n  - [Redis adapter](#redis-adapter)\n\n## Usage\n\n```ts\nimport { Server } from \"https://deno.land/x/socket_io@0.2.1/mod.ts\";\n\nconst io = new Server();\n\nio.on(\"connection\", (socket) =\u003e {\n  console.log(`socket ${socket.id} connected`);\n\n  socket.emit(\"hello\", \"world\");\n\n  socket.on(\"disconnect\", (reason) =\u003e {\n    console.log(`socket ${socket.id} disconnected due to ${reason}`);\n  });\n});\n\nDeno.serve({\n  handler: io.handler(),\n  port: 3000,\n});\n```\n\nAnd then run with:\n\n```\n$ deno run --allow-net index.ts\n```\n\nLike the [Node.js server](https://socket.io/docs/v4/typescript/), you can also\nprovide types for the events sent between the server and the clients:\n\n```ts\ninterface ServerToClientEvents {\n  noArg: () =\u003e void;\n  basicEmit: (a: number, b: string, c: Buffer) =\u003e void;\n  withAck: (d: string, callback: (e: number) =\u003e void) =\u003e void;\n}\n\ninterface ClientToServerEvents {\n  hello: () =\u003e void;\n}\n\ninterface InterServerEvents {\n  ping: () =\u003e void;\n}\n\ninterface SocketData {\n  user_id: string;\n}\n\nconst io = new Server\u003c\n  ClientToServerEvents,\n  ServerToClientEvents,\n  InterServerEvents,\n  SocketData\n\u003e();\n```\n\n### With oak\n\nYou need to use the [.handle()](https://github.com/oakserver/oak#handle-method)\nmethod:\n\n```ts\nimport { Server } from \"https://deno.land/x/socket_io@0.2.0/mod.ts\";\nimport { Application } from \"https://deno.land/x/oak@14.2.0/mod.ts\";\n\nconst app = new Application();\n\napp.use((ctx) =\u003e {\n  ctx.response.body = \"Hello World!\";\n});\n\nconst io = new Server();\n\nio.on(\"connection\", (socket) =\u003e {\n  console.log(`socket ${socket.id} connected`);\n\n  socket.emit(\"hello\", \"world\");\n\n  socket.on(\"disconnect\", (reason) =\u003e {\n    console.log(`socket ${socket.id} disconnected due to ${reason}`);\n  });\n});\n\nconst handler = io.handler(async (req) =\u003e {\n  return await app.handle(req) || new Response(null, { status: 404 });\n});\n\nDeno.serve({\n  handler,\n  port: 3000,\n});\n```\n\n## Options\n\n### `path`\n\nDefault value: `/socket.io/`\n\nIt is the name of the path that is captured on the server side.\n\nCaution! The server and the client values must match (unless you are using a\npath-rewriting proxy in between).\n\nExample:\n\n```ts\nconst io = new Server(httpServer, {\n  path: \"/my-custom-path/\",\n});\n```\n\n### `connectTimeout`\n\nDefault value: `45000`\n\nThe number of ms before disconnecting a client that has not successfully joined\na namespace.\n\n### `pingTimeout`\n\nDefault value: `20000`\n\nThis value is used in the heartbeat mechanism, which periodically checks if the\nconnection is still alive between the server and the client.\n\nThe server sends a ping, and if the client does not answer with a pong within\n`pingTimeout` ms, the server considers that the connection is closed.\n\nSimilarly, if the client does not receive a ping from the server within\n`pingInterval + pingTimeout` ms, the client also considers that the connection\nis closed.\n\n### `pingInterval`\n\nDefault value: `25000`\n\nSee [`pingTimeout`](#pingtimeout) for more explanation.\n\n### `upgradeTimeout`\n\nDefault value: `10000`\n\nThis is the delay in milliseconds before an uncompleted transport upgrade is\ncancelled.\n\n### `maxHttpBufferSize`\n\nDefault value: `1e6` (1 MB)\n\nThis defines how many bytes a single message can be, before closing the socket.\nYou may increase or decrease this value depending on your needs.\n\n### `allowRequest`\n\nDefault value: `-`\n\nA function that receives a given handshake or upgrade request as its first\nparameter, and can decide whether to continue or not.\n\nExample:\n\n```ts\nconst io = new Server({\n  allowRequest: (req, connInfo) =\u003e {\n    return Promise.reject(\"thou shall not pass\");\n  },\n});\n```\n\n### `cors`\n\nDefault value: `-`\n\nA set of options related to\n[Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)\n(CORS).\n\nExample:\n\n```ts\nconst io = new Server({\n  cors: {\n    origin: [\"https://example.com\"],\n    allowedHeaders: [\"my-header\"],\n    credentials: true,\n  },\n});\n```\n\n### `editHandshakeHeaders`\n\nDefault value: `-`\n\nA function that allows to edit the response headers of the handshake request.\n\nExample:\n\n```ts\nconst io = new Server({\n  editHandshakeHeaders: (responseHeaders, req, connInfo) =\u003e {\n    responseHeaders.set(\"set-cookie\", \"sid=1234\");\n  },\n});\n```\n\n### `editResponseHeaders`\n\nDefault value: `-`\n\nA function that allows to edit the response headers of all requests.\n\nExample:\n\n```ts\nconst io = new Server({\n  editResponseHeaders: (responseHeaders, req, connInfo) =\u003e {\n    responseHeaders.set(\"my-header\", \"abcd\");\n  },\n});\n```\n\n## Logs\n\nThe library relies on the standard `log` module, so you can display the internal\nlogs of the Socket.IO server with:\n\n```ts\nimport * as log from \"https://deno.land/std@0.166.0/log/mod.ts\";\n\nawait log.setup({\n  handlers: {\n    console: new log.handlers.ConsoleHandler(\"DEBUG\"),\n  },\n  loggers: {\n    \"socket.io\": {\n      level: \"DEBUG\",\n      handlers: [\"console\"],\n    },\n    \"engine.io\": {\n      level: \"DEBUG\",\n      handlers: [\"console\"],\n    },\n  },\n});\n```\n\n## Adapters\n\nCustom adapters can be used to broadcast packets between several Socket.IO\nservers.\n\n### Redis adapter\n\nDocumentation: https://socket.io/docs/v4/redis-adapter/\n\n```js\nimport {\n  createRedisAdapter,\n  createRedisClient,\n  Server,\n} from \"https://deno.land/x/socket_io@0.2.0/mod.ts\";\n\nconst [pubClient, subClient] = await Promise.all([\n  createRedisClient({\n    hostname: \"localhost\",\n  }),\n  createRedisClient({\n    hostname: \"localhost\",\n  }),\n]);\n\nconst io = new Server({\n  adapter: createRedisAdapter(pubClient, subClient),\n});\n\nDeno.serve({\n  handler: io.handler(),\n  port: 3000,\n});\n```\n\n## License\n\n[ISC](/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-deno","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketio%2Fsocket.io-deno","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-deno/lists"}