{"id":13565885,"url":"https://github.com/alphaeadevelopment/bind-socketio-handlers","last_synced_at":"2026-01-20T22:37:57.025Z","repository":{"id":80756063,"uuid":"126628757","full_name":"alphaeadevelopment/bind-socketio-handlers","owner":"alphaeadevelopment","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-24T15:30:53.000Z","size":181,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T14:41:00.718Z","etag":null,"topics":[],"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/alphaeadevelopment.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-03-24T18:31:23.000Z","updated_at":"2021-11-10T08:30:07.000Z","dependencies_parsed_at":"2024-01-19T06:58:17.720Z","dependency_job_id":"6e7adef1-0d3d-428c-8f1f-47228b38e207","html_url":"https://github.com/alphaeadevelopment/bind-socketio-handlers","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"f826adef76149dbe5c830a074e4bcc948cf05ed1"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphaeadevelopment%2Fbind-socketio-handlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphaeadevelopment%2Fbind-socketio-handlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphaeadevelopment%2Fbind-socketio-handlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphaeadevelopment%2Fbind-socketio-handlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphaeadevelopment","download_url":"https://codeload.github.com/alphaeadevelopment/bind-socketio-handlers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247097604,"owners_count":20883121,"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-08-01T13:01:57.231Z","updated_at":"2026-01-20T22:37:56.986Z","avatar_url":"https://github.com/alphaeadevelopment.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# bind-socketio-handlers\n\n## Overview\nOn each client connection to a socket.io server, this library binds events received on the client socket to handler functions.\n\nIt also provides convenient helper methods to those helper functions.\n\n## Usage\n\n```javascript\n// handlers.js\nexport const sayHello = (callbacks, io, socket) =\u003e // handle event\n```\n\n```javascript\n// express.js\nimport express from 'express';\nimport socketIo from 'socket.io';\nimport bindSocketIoHandlers from 'bind-socketio-handlers';\nimport * as handlers from './handlers';\n\nconst onClientConnect = io =\u003e socket =\u003e {\n  bindSocketIoHandlers(io, socket, handlers);\n};\n\nconst app = express();\nconst io = socketIo(app);\nio.on('connection', onClientConnect(io));\n```\n\n## Callbacks\n\nThe `callbacks` object passed to each handler contains some helper functions:\n\n```javascript\n{\n  toSocket(event, payload),\n  toRoom(roomName)(event, payload),\n  joinRoom(roomName),\n  leaveRoom(roomName),\n  emitError(e, parameters),\n  onError(e, parameters), // alias for emitError\n}\n```\n\nAll default callback functions return a promise that resolve to undefined.\n\nYou can extend or over-write these callbacks by passing an object of named callback functions to `bindSocketIoHandlers`:\n\n```javascript\n  const myCallbacks = (socket) =\u003e ({\n    sayHiBack: () =\u003e socket.emit('Hi, back.'),\n  });\n  bindSocketIoHandlers(io, socket, handlers, myCallbacks(socket));\n```\n\nThese methods will then be accessible along with the default callbacks in your handler function:\n\n```javascript\n// handlers.js\nexport const sayHello = ({ sayHi }) =\u003e sayHi();\n```\n\n## Error handling\nIf your handler returns a promise that rejects, or if it throws an error, the client socket will be sent an event of type `'applicationError'`, with the error message as a payload:\n\n```javascript\n// handlers.js\nexport const sayHello = ({ sayHi }) =\u003e Promise.reject(new Error('not today, thanks'));\n```\nwill result in:\n```javascript\nsocket.emit('applicationError', { message: 'not today, thanks' });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphaeadevelopment%2Fbind-socketio-handlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphaeadevelopment%2Fbind-socketio-handlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphaeadevelopment%2Fbind-socketio-handlers/lists"}