-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas_new_comment.js
68 lines (50 loc) · 1.45 KB
/
has_new_comment.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Created by ZE on 26/09/15.
*/
//function handler(req, res) {
// res.writeHead(200);
// res.end('');
//}
var SSL_KEY = '/etc/letsencrypt/live/photoshare.space/privkey.pem';
var SSL_CERT = '/etc/letsencrypt/live/photoshare.space/cert.pem';
var CA = '/etc/letsencrypt/live/photoshare.space/chain.pem';
var fs = require('fs');
var httpsOptions = {
key: fs.readFileSync(SSL_KEY).toString(),
cert: fs.readFileSync(SSL_CERT).toString(),
ca: fs.readFileSync(CA).toString()
};
var app = require('https').createServer(httpsOptions);
var io = require('socket.io').listen(app);
app.listen(6001, function () {
console.log('Server is running! at Port:' + String(6001));
});
io.on('connection', function (socket) {
//
console.log(socket.id);
});
var Redis = require('ioredis');
var redis = new Redis(
{
port: 6379, // Redis port
host: '153.120.167.173', // Redis host
family: 4, // 4 (IPv4) or 6 (IPv6)
password: 'OYtjt7TRs72StScD2mI4Lfsl5Ce0',//'OYtjt7TRs72StScD2mI4Lfsl5Ce0',
db: 0
}
);
redis.psubscribe('*', function (err, count) {
//
console.log('psubscribe');
console.log(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.data);//
});