socket.io-handler
Init socket.io and set event handlers in a structured way.
Features
- Used with express.js
- Callback as ES6 generator
How to use
Boot express.js and start socket.io:
const express = ;const app = ;const port = 3300; const server = app; /** * Boot socket.io */const handler = server;
Append handlers from files:
handler;handler;
Append handlers directly:
handler; handler;
Note: For multiple defined events, all functions will be triggered.
APIs
handler.require(path)
Append handlers from a file
handler.defineEvents(eventMap)
Append handlers from a JSON object
handler.defineEvent(eventName, cb)
Append a handler for an event
Development
npm installnpm run example
And you should get output like
> node example/app.js
Listening for the socket.io events: [ 'userLogin', 'userUpdate', 'userInfo' ]
Express server started at port: 3300
Use your own socket.io client and have fun. :)