Is it possible to run some script and if client connected pass arguments to it, something like this:
var io = require('socket.io').listen(http);
io.sockets.on('connection', function (client) {
console.log('Client connected');
var notifikacija = function (array) {
client.emit('populate', array);
}
});
///////////////////////////////////////////////////////////////////////
setInterval(function(){
var array = newArray();
array[0]='test';
notifikacija(array);
}, 2000);
Now it shows error: notifikacija is not defined. It is quite a strugle…
The
notifikacijafunction is local to the scope of the io.sockets.on handler. You want it to be global so that you can access it in setInterval:Here’s a blog post with some more information on scope in Javascript.