I subscibe to laravel 5 event[channal] update.group
and I recive message in console after I trigger event but on client side in browser I don't recive any message. Also after I trigger event I recive message in console and then node server stop working with message:
bash-4.2# node node.js
Listening on Port 3000
Message Recieved: testasdsa
/home/client/public_html/node_modules/ioredis/lib/parsers/javascript.js:216
throw err;
^
SyntaxError: Unexpected token e
at Object.parse (native)
at Redis.<anonymous> (/home/client/public_html/node_modules/node.js:10:20)
at Redis.emit (events.js:110:17)
at Redis.exports.returnReply (/home/client/public_html/node_modules/ioredis/lib/redis/parser.js:79:16)
at ReplyParser.<anonymous> (/home/client/public_html/node_modules/ioredis/lib/redis/parser.js:27:10)
at ReplyParser.emit (events.js:107:17)
at ReplyParser.send_reply (/home/client/public_html/node_modules/ioredis/lib/parsers/javascript.js:281:8)
at ReplyParser.execute (/home/client/public_html/node_modules/ioredis/lib/parsers/javascript.js:210:14)
at Socket.<anonymous> (/home/client/public_html/node_modules/ioredis/lib/redis/event_handler.js:90:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Here is my node.js file:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('update.group', function(err, count) {
});
redis.on('message', function(channel, message) {
console.log('Message Recieved: ' + message);
message = JSON.parse(message);
io.sockets.emit(channel + ':' + message.event, message.data);
});
http.listen(3000, function(){
console.log('Listening on Port 3000');
});
And for client side:
var socket = io.connect('127.0.0.1:3000');
socket.on("update.group", function(message){
// increase the power everytime we load test route
console.log(message);
});
Anyone can find what is problem?