{"id":13718765,"url":"https://github.com/ericls/oak-channels","last_synced_at":"2025-08-17T16:48:11.184Z","repository":{"id":57675558,"uuid":"400691253","full_name":"ericls/oak-channels","owner":"ericls","description":"Trying to make it easier to write real world websocket applications in oak","archived":false,"fork":false,"pushed_at":"2021-09-16T02:15:29.000Z","size":31,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T06:25:01.180Z","etag":null,"topics":["deno","oak","websocket"],"latest_commit_sha":null,"homepage":"https://deno.land/x/oak_channels","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-28T03:23:18.000Z","updated_at":"2023-03-14T03:53:44.000Z","dependencies_parsed_at":"2022-09-26T20:41:34.052Z","dependency_job_id":null,"html_url":"https://github.com/ericls/oak-channels","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Foak-channels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Foak-channels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Foak-channels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Foak-channels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericls","download_url":"https://codeload.github.com/ericls/oak-channels/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238397306,"owners_count":19465147,"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","oak","websocket"],"created_at":"2024-08-03T01:00:37.277Z","updated_at":"2025-02-12T01:33:37.504Z","avatar_url":"https://github.com/ericls.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nInspired by django-channels. oak-channels makes it easier to write real world websocket applications.\n\noak-channels introduces two concepts: `Consumer` and `Layer`.\n\n`Consumer` represents the websocket connection between a client and the server, it maintains a one-to-one relationship between a client and server and provides some helper method to send and receive messages. `Layer` facilitates sending messages across different application processes and allows consumers to join/leave groups and exchange messages within a group, it maintains many-to-many relationships between groups and consumers. \n\nThis diagram illustrates their relationships:\n\n\u003cimg src=\"https://i.imgur.com/BfqABO3.png\" width=\"300\" /\u003e\n\nBuilt-in layers:\n- InMemory (doesn't work across processes)\n- BroadcastChannel (works with deno deploy, not fully tested)\n- RedisPubSub\n\n# Quick start\nThe following is a simple example on the usage of oak-channels:\n```typescript\nimport {\n  Application,\n  HttpServerStd,\n  Router,\n} from \"https://deno.land/x/oak@v9.0.0/mod.ts\";\nimport {\n  BaseConsumer,\n  InMemoryLayer,\n  mountConsumer,\n} from \"https://deno.land/x/oak_channels/mod.ts\";\n\nconst app = new Application({ serverConstructor: HttpServerStd });\nconst router = new Router();\nconst layer = new InMemoryLayer();\n\nclass EchoConsumer extends BaseConsumer {\n  async onConnect() {\n    // add this consumer to group \"foo\"\n    await this.groupJoin(\"foo\");\n    // send group message to all consumers in group \"foo\", including \"self\"\n    await this.layer.groupSend(\"foo\", \"new user joined\");\n  }\n\n  // handle group messages\n  async onGroupMessage(group: string, message: string | Uint8Array) {\n    this.send(`${group} says ${message}`)\n  }\n\n  // handle client messages\n  async onText(text: string) {\n    this.send(text);\n  }\n}\n\nrouter.all(\"/ws\", mountConsumer(EchoConsumer, layer));\napp.use(router.routes());\nawait app.listen({ port: 8000 });\n```\n\nAn example with client side code can be found in `examples/example-echo.ts`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Foak-channels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericls%2Foak-channels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Foak-channels/lists"}