Created
December 12, 2017 09:56
-
-
Save nxmad/e7f6eebb6addf25286642af27a40b4d3 to your computer and use it in GitHub Desktop.
This file contains 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
let app = require('http').createServer((req, res) => { | |
res.writeHead(200); | |
res.end('!@#'); | |
}) | |
let io = require('socket.io').listen(app) | |
app.listen(process.env.WS_PORT) | |
let Redis = require('redis').createClient({ | |
host: process.env.REDIS_HOST, | |
port: process.env.REDIS_PORT, | |
}); | |
const Handler = (channel, message) => { | |
message = JSON.parse(message); | |
let data = message.data; | |
let event = message.event.split('\\').reverse()[0]; | |
Listener.fire(channel, event, data); | |
} | |
const Listener = { | |
fire(channel, event, data) { | |
if (this[channel].hasOwnProperty(event)) { | |
this[channel][event](data); | |
} | |
}, | |
Channel: { | |
Event(data) { | |
} | |
}, | |
} | |
Redis.on('message', Handler) | |
Redis.subscribe('Channel') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment