-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.js
40 lines (31 loc) · 792 Bytes
/
chat.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Created by ZE on 26/09/15.
*/
function handler(req, res) {
res.writeHead(200);
res.end('');
}
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var Redis = require('ioredis');
var redis = new Redis();
app.listen(6001, function () {
console.log('Server is running! at Port:' + String(6001));
});
io.on('connection', function (socket) {
//
console.log(socket.id);
});
redis.psubscribe('*', function (err, count) {
//
});
//
redis.on('pmessage', function (subscribed, channel, message) {
console.log('emitting');
console.log(channel);
message = JSON.parse(message);
console.log(message);
//emit channel
//ex. user.1:App\Events\Chat
io.emit(channel + ':' + message.event, message.data);//
});