I trying to push notification to specific client with nodejs and redis but emitting the notification to the requested user is not working
my codes in php and nodejs and client is below:
//Nodejs Server ---------------------------
var io = require('socket.io').listen(3000);
var redis = require('redis');
var $clients = {};
var $notifySubscribe = redis.createClient();
var $loginUserSubscribe = redis.createClient();
$notifySubscribe.subscribe('notify');
$loginUserSubscribe.subscribe('loginUser');
$notifySubscribe.on('message', function($channel, $message) {
var $data = JSON.parse($message);
if($data.userId in $clients){
$clients[$data.userId].emit('updateNotifications', '+1');
}
});
io.sockets.on('connection', function(socket) {
$loginUserSubscribe.on('message', function($channel, $message){
var $data = JSON.parse($message);
if(!($data.userId in $clients)){
$clients[$data.userId] = socket;
}
});
});
//Client ----------------------------------
socketIo.on('updateNotifications', function($count){
alert($count);
});
//Php Server ------------------------------
$data = array('userId' => 20584, 'username' => 'mohammadsaleh');
$this->__redis->publish("notify", json_encode($data));