{"id":15133001,"url":"https://github.com/dotstudio-io/fi-sockets","last_synced_at":"2025-09-29T02:32:18.932Z","repository":{"id":57235096,"uuid":"47357683","full_name":"dotstudio-io/fi-sockets","owner":"dotstudio-io","description":"Sockets module loader for socket.io Node.js apps","archived":true,"fork":false,"pushed_at":"2020-04-02T13:47:30.000Z","size":2117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-17T18:24:17.195Z","etag":null,"topics":["loader","namespace","socket","socket-io","socket-modules","socketio"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotstudio-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-03T20:16:04.000Z","updated_at":"2023-01-28T15:12:50.000Z","dependencies_parsed_at":"2022-08-23T16:30:22.962Z","dependency_job_id":null,"html_url":"https://github.com/dotstudio-io/fi-sockets","commit_stats":null,"previous_names":["finaldevstudio/fi-sockets"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotstudio-io%2Ffi-sockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotstudio-io%2Ffi-sockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotstudio-io%2Ffi-sockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotstudio-io%2Ffi-sockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotstudio-io","download_url":"https://codeload.github.com/dotstudio-io/fi-sockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234583683,"owners_count":18856280,"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":["loader","namespace","socket","socket-io","socket-modules","socketio"],"created_at":"2024-09-26T04:42:33.157Z","updated_at":"2025-09-29T02:32:13.617Z","avatar_url":"https://github.com/dotstudio-io.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n### No longer maintained.\n---\n\n# Fi Sockets\nSockets module loader for socket.io Node.js applications.\n\n## Installing\n\n```sh\nnpm install --save fi-sockets\n```\n\n## Usage\n\n```js\nconst sockets = require('fi-sockets');\n```\n\n### Initialization\nYou must call it with your App's Server instance and a configuration object:\n\n```js\nconst sockets = require('fi-sockets');\nconst http = require('http');\nconst path = require('path');\n\nconst server = http.createServer();\n\nsockets.init(server, config);\n\nserver.listen(0);\n\nconsole.log(`Server running on ${ server.address().port }`);\n```\n\n### Configuration\nThe first argument is required and must be your application's Server instance. The socket.io instance will be attached to it.\n\nThe second argument is also required and it must be an `Object` with the following parameters:\n- **debug**: This parameter can be a `Function` to log with or a `Boolean`. If `true` it will use `console.log`.\n- **basedir**: This is required and must be a `String`. This should point to the absolute path where the socket module's scripts are located.\n- **arguments**: This is optional and can be an `Array` to apply to each socket module right after the default `nsp` and `io` arguments.\n- **adapter**: This is optional and it must be a socket.io adapter function.\n- **options**: This is optional and it's passed directly to `io` as the options argument.\n\n#### Example Configuration\n\n```js\n'use strict';\n\nconst redis = require('socket.io-redis');\nconst debug = require('debug');\nconst path = require('path');\n\nmodule.exports = {\n\n  basedir: path.normalize(path.join(__dirname, '..', 'sockets')),\n\n  debug: debug('app:sockets'),\n\n  arguments: [],\n\n  adapter: redis({\n    host: 'localhost',\n    port: 6379\n  })\n\n};\n```\n\n### Socket Modules\nThe socket modules inside your `config.basedir` folder must be like this:\n\n```js\n'use strict';\n\nconst debug = require('debug')('app:sockets');\n\nmodule.exports = nsp =\u003e {\n\n  nsp.on('connection', socket =\u003e {\n\n    debug(`A user connected to ${ nsp.name }`);\n\n    socket.on('disconnect', () =\u003e {\n      debug(`A user disconnected from ${ nsp.name }`);\n    });\n\n  });\n\n};\n```\n\nThe exported function will receive the *namespace* instance as created with `io.of(namespace)`, the current *socket.io* instance and the applied `config.arguments`. The *namespace* is created with the module's file name. If the module's file name is `index.js` then it'll be converted to `/`.\n\nFolders are also respected, so if a socket module is located in `\u003c...\u003e/sockets/chat/messaging.js` then it's *namespace* will be `/chat/messaging` and if it's file name is `index.js` inside that same folder then it's *namespace* will be `/chat`.\n\nThe first two arguments will always be the generated *namespace* and the *socket.io* instance so you can define your socket *namespace* behavior. The rest of the parameters will be the ones you define in the `config.arguments` `Array`:\n\n```js\nconfig.arguments = [\n  /* Second argument */\n  session,\n\n  /* Third argument */\n  function aFunction() {\n    //...\n  }\n\n  /* And so on... */\n];\n```\n\nWill be passed as:\n\n```js\n/* mongoose.Schema will always be the first argument */\nmodule.exports =  function (nsp, io, session, aFunction) {\n\n  nsp.on('connection', function (socket) {\n    //...\n  });\n\n};\n```\n\n### Properties\nThe Sockets component exposes the following properties:\n- **init**: The initialization `Function`. Must be called before anything else with an options parameter as shown in the [Initialization](#initialization) example.\n- **io**: The current socket.io instance.\n- **modules**: An `Object` that contains all the *namespaces* as properties.\n- **of**: A convenient method to retrieve the socket modules by its *namespace* path or name:\n\n  ```js\n  /* These will both return the [chat] namespace */\n  sockets.of('chat').emit('hello', 'everyone!');\n  sockets.of('/chat').emit('hello', 'everyone!');\n\n  /* These will both return the [chat/messaging] namespace */\n  sockets.of('/chat/messaging').emit('hello', 'everyone!');\n  sockets.of('chat/messaging').emit('hello', 'everyone!');\n  ```\n\n  If passed an empty `String` or a *falsy* value then it'll return the root *namespace* if it exists:\n\n  ```js\n  /* These will all return the root namespace ('/') */\n  sockets.of('/').emit('hello', 'everyone!');\n  sockets.of('').emit('hello', 'everyone!');\n  sockets.of().emit('hello', 'everyone!');\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotstudio-io%2Ffi-sockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotstudio-io%2Ffi-sockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotstudio-io%2Ffi-sockets/lists"}