Created
February 18, 2016 21:29
-
-
Save juice49/da39b4983af138f9c865 to your computer and use it in GitHub Desktop.
Websocket router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function routeWebsocket(server, controllers = []) { | |
server.on('connection', client => { | |
client.on('message', ({ event, data }) => { | |
const controller = controllers[event]; | |
if(controller) { | |
controller(data); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment