aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/assets/js/chatServer.js
blob: fb6c7fc56ad53cd72f9c8f1a8f54ac7d5a7973af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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();
    });
});