{"id":19938768,"url":"https://github.com/raphaelbs/socketio-server","last_synced_at":"2025-03-01T12:45:17.970Z","repository":{"id":57365572,"uuid":"68475234","full_name":"raphaelbs/socketio-server","owner":"raphaelbs","description":"A tool to easily create and use SocketIO-Rooms inside nodejs-express-routes.","archived":false,"fork":false,"pushed_at":"2018-10-27T21:52:36.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T10:14:32.934Z","etag":null,"topics":["nodejs-modules","npm-package","session-management","socketio","socketio-server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/raphaelbs.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":"2016-09-17T20:00:02.000Z","updated_at":"2020-04-22T11:43:46.000Z","dependencies_parsed_at":"2022-08-23T19:00:57.083Z","dependency_job_id":null,"html_url":"https://github.com/raphaelbs/socketio-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelbs%2Fsocketio-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelbs%2Fsocketio-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelbs%2Fsocketio-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelbs%2Fsocketio-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raphaelbs","download_url":"https://codeload.github.com/raphaelbs/socketio-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241367926,"owners_count":19951444,"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":["nodejs-modules","npm-package","session-management","socketio","socketio-server"],"created_at":"2024-11-12T23:41:55.578Z","updated_at":"2025-03-01T12:45:17.950Z","avatar_url":"https://github.com/raphaelbs.png","language":"JavaScript","readme":"# socketio-server\nA tool to easily create and use SocketIO rooms inside nodejs routes.\n\n#### Please Note\n\nThis package was built upon [socket.io](https://www.npmjs.com/package/socket.io).\nKnow the [api](https://www.npmjs.com/package/socket.io#api) especially the [socket](https://www.npmjs.com/package/socket.io#socket) section to get the best out of it.\n\n## Installation\n\nuse your http server as parameter\n\n```javascript\nvar http = require('http');\nrequire('socketio-server')(http, {debug: true});\n```\n\nor your server instance of express\n\n```javascript\nvar http = require('http');\nvar server = http.createServer(app);\nrequire('socketio-server')(server, {debug: true});\n```\n\n## Usage\n\nIn the client application, the first step is to emit an event named **_register_** with an identifier that you keep track. In the example bellow I've used my username as the identifier:\n\n```javascript\n// this can be found laying in some Angular directive frontend application\n\n// an socket for the room 'chat'\nlet socket = io.connect('http://localhost:3000/chat');\nsocket.on('connect', function(socket){\n    // here's the 'register' call\n    socket.emit('register', 'raphaelbs');\n\n    // ... any other event assign\n    socket.on('foo', function(bar){\n        console.log(bar);\n    });\n});\n```\n\nInside the NodeJS server, the registered socket can be retrieved at any time using the identifier\n\n```javascript\nvar express = require('express');\nvar router = express.Router();\nvar socket = require('socketio-server');\nvar chatRoom = socket('chat');\n\nrouter.get('/', function(req, res) {\n    // using the common identifier we can retrieve the correcty socket inside the router\n\tchatRoom('raphaelbs', function(err, socket){\n\t\tif(err) return console.error(err);\n\t\t// this socket instance is an socket.io socket\n\t\tvar bar = 10;\n\t\t// only the event 'foo' of 'raphaelbs' will receive this 'bar'\n\t\tsocket.emit('foo', bar);\n\t});\n});\n\nmodule.exports = router;\n\n```\n\n## Reference\n\n### require('socketio-server')([params](#constructor-argument-params)[, [options](#constructor-argument-options)])\n\u003e_return [function(id, callback)](#requiresocketio-serverroom-nameid-callback)_\n\nThe main entry point of this module.\n\n#### Constructor argument: params\n\u003e type _string_ or _object_\n\nIf you need to initialize the module, you should supply the server as argument:\n```javascript\nvar http = require('http');\nvar server = http.createServer(app);\nrequire('socketio-server')(server, {debug: true});\n```\n\nIf you are in the **use** stage, the _params_ argument could serve as **Room identifier**:\n```javascript\nvar socket = require('socketio-server');\nvar chatRoom = socket('chat'); //creates (if not created) and exposes a room named 'chat'\nvar mainRoom = socket(); //creates (if not created) and exposes the default '/' room\n```\n\n#### Constructor argument: options\n\u003e type _object_\n\nkey | description | type | default\n--- | --- | --- | ---\n*debug* | Enable verbosity for debuggin (very handy) | boolean | false\n\n### require('socketio-server')('room name')(id, callback)\n\nThis function is the goal of the module. Within this function, you can specifically get the socket of the desired ID defined in your client-side.\n\n#### id\n\u003e type string\n\nThe identifier of the socket that you want to retrieve.\n\n#### callback\n\u003e type function(err, socket)\n\nThis callback function exposes a [socket](https://www.npmjs.com/package/socket.io#socket) object relative to the identifier above.\n\n## Dependencies\n\nsocket.io\n\n## Contact-me\n* [Email](mailto:raphael.b.souza@hotmail.com)\n* [Facebook](https://facebook.com/raphaelbs)\n* [GitHub](https://github.com/raphaelbs)\n* [NPM](https://npmjs.com/~raphaelbs)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelbs%2Fsocketio-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphaelbs%2Fsocketio-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelbs%2Fsocketio-server/lists"}