I am trying to create a real time live chat with Laravel 5.1 (I am using AsgardCMS), Redis and Socket.IO. My logic is when a guest user opens the chat window to fire an event to a specific operator user. To do so I am broadcasting the event to a channel (channel-name)+(operator id)
, because I want to show a notification to a specific operator, who is logged in the backend of the website. What I find difficult is how to get the id of the operator in the server side code for Redis, which is listening for events. This is the code:
var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('asgardcms.notifications.3');
redis.on('message', function(channel, message) {
console.log(channel, message);
message = JSON.parse(message);
io.emit(channel + ':' + message.event, message.data);
});
io.sockets.on('connection', function (socket){
// console.log(socket);
});
server.listen(3000);
Here I have hardcoded 3
in the name of the channel but I want this value to change so I can notify a certain operator.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire