I am trying to execute functions on the client side from a node server using socket.io. The data is getting to the client side no problem but I am not able to execute functions on connect.
My server code (emit in a loop):
var io = require('socket.io')(server);
io.on('connection', function(client){
setInterval(function(){
client.emit('for_client', datatosend);
}, 100);
});
My client side code:
socket.on('for_client', function (data) {
console.log(data);
switch(true) {
case (data == "reload"):
console.log('DO reload'); //<<< not working
break;
case (data == "switch"):
console.log('DO switch'); //<<< not working
break;
default:
console.log(data); //<<< this DOES work
}
});
And here is proof the data is coming through ;)
Any help is super appreciated.
via andehlu
No comments:
Post a Comment