{"id":16322739,"url":"https://github.com/shellscape/koa-ws","last_synced_at":"2025-09-13T15:32:12.617Z","repository":{"id":19482880,"uuid":"22728580","full_name":"shellscape/koa-ws","owner":"shellscape","description":"Empower your koa.js application with realtime","archived":false,"fork":false,"pushed_at":"2019-12-30T14:44:59.000Z","size":123,"stargazers_count":26,"open_issues_count":5,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-30T06:59:46.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shellscape.png","metadata":{"files":{"readme":"README-old.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"shellscape","patreon":"shellscape","custom":"https://paypal.me/shellscape","liberapay":"shellscape"}},"created_at":"2014-08-07T16:41:15.000Z","updated_at":"2019-10-29T23:14:19.000Z","dependencies_parsed_at":"2022-08-21T08:11:17.999Z","dependency_job_id":null,"html_url":"https://github.com/shellscape/koa-ws","commit_stats":null,"previous_names":["mekwall/koa-ws"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellscape%2Fkoa-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellscape%2Fkoa-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellscape%2Fkoa-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellscape%2Fkoa-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shellscape","download_url":"https://codeload.github.com/shellscape/koa-ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232885585,"owners_count":18591830,"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":[],"created_at":"2024-10-10T22:52:16.299Z","updated_at":"2025-01-07T13:36:43.335Z","avatar_url":"https://github.com/shellscape.png","language":"JavaScript","readme":"# koa-ws\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Coveralls][coveralls-image]][coveralls-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n[![Gittip][gittip-image]][gittip-url]\n\n[npm-image]: https://img.shields.io/npm/v/koa-ws.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-ws\n[travis-image]: https://img.shields.io/travis/mekwall/koa-ws.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mekwall/koa-ws\n[coveralls-image]: https://img.shields.io/coveralls/mekwall/koa-ws.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/mekwall/koa-ws?branch=master\n[david-image]: https://img.shields.io/david/mekwall/koa-ws.svg?style=flat-square\n[david-url]: https://david-dm.org/mekwall/koa-ws\n[node-image]: https://img.shields.io/badge/node.js-%3E=_0.11-red.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/koa-ws.svg?style=flat-square\n[download-url]: https://npmjs.org/package/koa-ws\n[gittip-image]: https://img.shields.io/gittip/mekwall.svg?style=flat-square\n[gittip-url]: https://www.gittip.com/mekwall/\n\nEmpower your koa.js application with realtime, using the battle tested ws library.\n\n## Features\n\n* Uses jsonrpc 2.0 protocol per default\n* Uses generators as method handlers\n* Simple API to register namespaced methods\n* Shared koa session between HTTP and WebSocket\n\n## Quick start\n\n### Installation\n\n    $ npm install koa-ws\n\n### Usage\n\nAdd realtime to your koa app with a couple of lines:\n\n    var koa = require('koa');\n    var koaws = require('koa-ws');\n    var app = koa();\n\n    var options = {\n        serveClientFile: true,\n        clientFilePath: '/koaws.js',\n        heartbeat: true,\n        heartbeatInterval: 5000\n    };\n\n    app.use(koaws(app, options));\n\n    app.listen(3000);\n\nRegister a simple method on the server:\n\n    app.ws.register('hello', function* () {\n        this.result('world!');\n    });\n\nLoad the client library in the browser with require (`var koaws = require('koa-ws/client')`) or use the hosted version at `/koaws.js`.\n\nRegister a method on the client to recieve the session:\n\n    koaws.register('session', function (err, payload) {\n        if (err) console.error('Something went wrong', err);\n        console.log(payload) // should include our session\n    });\n\nConnect to the server:\n\n    koaws.connect();\n\nCall the method from the client:\n\n    koaws.method('hello', function (err, result) {\n        if (err) console.error('Something went wrong', err);\n        console.log(result) // should log 'world!'\n    });\n\n#### Options\n\n##### heartbeat (default: true)\nIf server/client should send hearbeats to eachother\n\n##### heartbeatInterval (default: 5000)\nHow often the heartbeat should be sent\n\n##### serveClientFile (default: true)\nWill try and serve the client library file when `this.path` matches the `clientFilePath` option.\n\n##### clientFilePath (default: /koaws.js)\nDefines the path to match when serving the client library.\n\n### Examples\n\n#### Namespaced methods\n\nRegister a namespace:\n\n    app.ws.register('user', {\n        create: function* () {\n            // create user\n        },\n        update: function* () {\n            // update user\n        },\n        remove: function* () {\n            // remove user\n        }\n    });\n\nOn the client you can then emit:\n\n* `user:create`\n* `user:update`\n* `user:remove`\n\n\n## License\n\nCopyright (c) 2014, Marcus Ekwall marcus.ekwall@gmail.com\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","funding_links":["https://github.com/sponsors/shellscape","https://patreon.com/shellscape","https://paypal.me/shellscape","https://liberapay.com/shellscape"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellscape%2Fkoa-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshellscape%2Fkoa-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellscape%2Fkoa-ws/lists"}