{"id":24738629,"url":"https://github.com/zweifisch/einbahn","last_synced_at":"2026-04-10T07:38:30.341Z","repository":{"id":57221036,"uuid":"152258087","full_name":"zweifisch/einbahn","owner":"zweifisch","description":"Server-Sent Events with Namespaces and Channels","archived":false,"fork":false,"pushed_at":"2018-10-09T14:04:26.000Z","size":399,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T11:07:59.433Z","etag":null,"topics":["sse"],"latest_commit_sha":null,"homepage":null,"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/zweifisch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-10-09T13:42:07.000Z","updated_at":"2023-12-13T05:34:30.000Z","dependencies_parsed_at":"2022-08-29T04:01:46.964Z","dependency_job_id":null,"html_url":"https://github.com/zweifisch/einbahn","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Feinbahn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Feinbahn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Feinbahn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Feinbahn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweifisch","download_url":"https://codeload.github.com/zweifisch/einbahn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245006613,"owners_count":20546136,"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":["sse"],"created_at":"2025-01-27T22:55:06.326Z","updated_at":"2026-04-10T07:38:30.312Z","avatar_url":"https://github.com/zweifisch.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# einbahn\n\n[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Node.js Version][node-version-image]][node-version-url]\n\nServer-Sent Events with Namespaces and Channels\n\n- tested with http1, http2, koa and express\n- namespaces(like namespaces in socket.io or rabbitmq)\n- channels(like rooms in socket.io)\n- automatic keepalive\n- payload is json encoded\n\n## getting started\n\na minimal working example using koa\n\n``` js\nconst Koa = require('koa')\nconst {SSE, koaMiddleware} = require('einbahn')\nconst app = new Koa()\nconst sse = new SSE()\nsse.on('connection', client =\u003e {\n  client.send({event: 'welcome', data: 'message from server'})\n})\napp.use(koaMiddleware(sse))\napp.use((ctx, next) =\u003e {\n  ctx.body = `\u003chtml\u003e\u003cmeta charset='utf8'/\u003e\u003cscript\u003e\n  let es = new EventSource('/')\n  es.addEventListener('welcome', ({ data }) =\u003e {\n    alert(JSON.parse(data))\n  })\n\u003c/script\u003e\u003c/html\u003e`\n})\napp.listen(3000, err =\u003e console.log(err ? err : 'listen on http://localhost:3000'))\n```\n\n### namespaces\n\nby default all client are connected to the `/` namespace:\n\n``` js\nnew EventSource('/')\n```\n\nto connect to a specific namespace:\n\n``` js\nnew EventSource('/namespace1')\n```\n\nserver side code\n\n``` js\nconst ns1 = sse.of('/namespace1')\n// send event to all client within the namespace\nns1.send({event: 'time', data: new Date()})\n```\n\n### channels(rooms)\n\na namespace can have multiple channels, to join client to a channel:\n\n``` js\nsse.on('connection', (client, lastId, query) =\u003e {\n  client.join('chan1')\n  sse.to('chan1').send({data: new Date()})\n})\n```\n\n[documentation](https://zweifisch.github.io/einbahn/)\n\n[npm-image]: https://img.shields.io/npm/v/einbahn.svg?style=flat\n[npm-url]: https://npmjs.org/package/einbahn\n[travis-image]: https://img.shields.io/travis/zweifisch/einbahn.svg?style=flat\n[travis-url]: https://travis-ci.org/zweifisch/einbahn\n[node-version-image]: https://img.shields.io/node/v/einbahn.svg\n[node-version-url]: https://nodejs.org/en/download/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Feinbahn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweifisch%2Feinbahn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Feinbahn/lists"}