-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrabbit_handler.js
42 lines (29 loc) · 939 Bytes
/
rabbit_handler.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
var rabbitMQHandler = require('./rabbitMQ_messaging');
var os = require('os');
module.exports = rabbitHandler;
function rabbitHandler(io){
rabbitMQHandler('amqp://test_rabbit', function(err, options){
if(err){
throw err;
}
options.onMessageReceived = onMessageReceived;
io.on('connection', websocketConnect);
function websocketConnect(socket){
console.log('New connection')
io.emit('start', {ipHost: os.hostname()})
socket.on('disconnect', socketDisconnect);
socket.on('message', socketMessage);
function socketDisconnect(e){
console.log('Disconnect ', e);
}
function socketMessage(text){
var message = {text: text, date: new Date(), ip: os.hostname()};
// io.emit('message', message)
options.emitMessage(message);
}
}
function onMessageReceived(message){
io.emit('message', message)
}
});
}