routes for sockets
Socketron is an event-driven state machine for routing sockets.
I found when working with socket.io, that:
iosocketson'connection'var someState = ;socketon'this' ;socketon'that' ;socketon'the other thing' ;// ...;
Didn't scale very well. Organization became difficult, and much spaghetti code ensued.
Install with npm:
npm install socketron
Give it a socket.io instance and you're good to go!
var io = require'socket.io'listen80;var socketron = require'socketron';var router = socketroninitio;routerstatename: 'lobby'default: true // this is where newly connected sockets goon:statemoveAllTostateparentgetSubstate'game';state'game'stateplayerssocketid = x: 0 y: 0;stateplayerssocketidx = messagex;stateplayerssocketidy = messagey;statebroadcast'update:player' stateplayerssocketid;;