{"id":15043750,"url":"https://github.com/alxshelepenok/inversify-socket-utils","last_synced_at":"2025-08-19T22:32:21.920Z","repository":{"id":37336670,"uuid":"142067781","full_name":"alxshelepenok/inversify-socket-utils","owner":"alxshelepenok","description":"Some utilities for the development of socket.io application with InversifyJS.","archived":false,"fork":false,"pushed_at":"2024-12-09T19:25:10.000Z","size":5424,"stargazers_count":19,"open_issues_count":21,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-10T05:35:18.357Z","etag":null,"topics":["inversify","inversion-of-control","nodejs","socket-io","typescript","websockets"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/alxshelepenok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-23T20:48:50.000Z","updated_at":"2024-09-19T07:20:00.000Z","dependencies_parsed_at":"2022-07-09T05:00:22.344Z","dependency_job_id":"ec3610be-c44a-4576-97d3-6f4a7d293fdd","html_url":"https://github.com/alxshelepenok/inversify-socket-utils","commit_stats":{"total_commits":2607,"total_committers":8,"mean_commits":325.875,"dds":0.5638665132336018,"last_synced_commit":"e4a603e1b04e4a115771d73d2e494c73004ffaec"},"previous_names":[],"tags_count":1137,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxshelepenok%2Finversify-socket-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxshelepenok%2Finversify-socket-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxshelepenok%2Finversify-socket-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxshelepenok%2Finversify-socket-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alxshelepenok","download_url":"https://codeload.github.com/alxshelepenok/inversify-socket-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230374118,"owners_count":18216041,"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":["inversify","inversion-of-control","nodejs","socket-io","typescript","websockets"],"created_at":"2024-09-24T20:49:32.886Z","updated_at":"2025-08-19T22:32:21.912Z","avatar_url":"https://github.com/alxshelepenok.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inversify-socket-utils\n\nSome utilities for the development of socket.io applications with Inversify.\n\n## Installation\n\nYou can install `inversify-socket-utils` using npm:\n\n```sh\nnpm install inversify inversify-socket-utils reflect-metadata --save\n```\n\nPlease refer to the [InversifyJS documentation](https://github.com/inversify/InversifyJS?tab=readme-ov-file#-installation) to learn more about the installation process.\n\n## How to use\n\nStep 1: Create a controller.\n\n```ts\nimport \"reflect-metadata\";\n\nimport { injectable } from \"inversify\";\nimport { Socket } from \"socket.io\";\n\nimport {\n  connectedSocket,\n  controller,\n  onConnect,\n  onDisconnect,\n  onMessage,\n} from \"inversify-socket-utils\";\n\n@injectable()\n@controller(\"/namespace\")\nexport class MessageController {\n  @onConnect(\"connection\")\n  connection() {\n    console.log(\"client connected\");\n  }\n\n  @onDisconnect(\"disconnect\")\n  disconnect() {\n    console.log(\"client disconnected\");\n  }\n\n  @onMessage(\"message\")\n  message(@connectedSocket() socket: Socket) {\n    console.log(\"message received\");\n    socket.emit(\"message\", \"hello!\");\n  }\n}\n```\n\nStep 2: Configure container and server.\n\nConfigure the inversify container in your composition root as usual.\n\nThen, pass the container to the InversifySocketServer constructor. This will allow it to register all controllers and their dependencies from your container and attach them to the socket.io app.\nThen just call server.build() to prepare your app.\n\nIn order for the InversifySocketServer to find your controllers, you must bind them to the `TYPE.Controller` service identifier and tag the binding with the controller's name.\n\n```ts\nimport { createServer } from \"http\";\nimport { Container } from \"inversify\";\nimport { Server } from \"socket.io\";\n\nimport { MessageController } from \"./controllers/message\";\nimport {\n  interfaces,\n  InversifySocketServer,\n  TYPE,\n} from \"inversify-socket-utils\";\n\nconst container = new Container();\n\ncontainer.bind\u003cinterfaces.Controller\u003e(TYPE.Controller).to(MessageController);\n\nconst app = createServer();\n\nconst io = new Server(app, {\n  cors: {\n    origin: \"*\",\n  },\n});\n\nconst server = new InversifySocketServer(container, io);\nserver.build();\n\napp.listen(3000);\n\nconsole.log(\"Server is listening on port 3000\");\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2025 Alexander Shelepenok\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxshelepenok%2Finversify-socket-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falxshelepenok%2Finversify-socket-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxshelepenok%2Finversify-socket-utils/lists"}