diff options
Diffstat (limited to 'resources/assets/js/chatServer.js')
-rw-r--r-- | resources/assets/js/chatServer.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/resources/assets/js/chatServer.js b/resources/assets/js/chatServer.js new file mode 100644 index 0000000..fb6c7fc --- /dev/null +++ b/resources/assets/js/chatServer.js @@ -0,0 +1,26 @@ +var app = require('express')(); +var server = require('http').Server(app); +var io = require('socket.io')(server); +var redis = require('redis'); +var port = 8890; + +server.listen(port, function () { + console.log("Listening on " + port) +}); + +io.on('connection', function (socket) { + + console.log("new client connected"); + var redisClient = redis.createClient(); + redisClient.subscribe('message'); + + redisClient.on("message", function (channel, message) { + console.log("new message" + message); + socket.emit(channel, message); + }); + + socket.on('disconnect', function () { + console.log("client connected"); + redisClient.quit(); + }); +}); |