websocket - Does socket.io emit a lot of processing power? -


i have socket.io client needs listen if specific user logs in/out socket.io server did create function takes array of userid, , callback return user information if logged in/out. here's code:

        this.onuserconnected = function(arrayofuserid,cb){              if(typeof arrayofuserid != 'object'){                 return console.error('1st parameter not array');             }             socket.on('onuserconnected', function(user) {               if(arrayofuserid.indexof(user.user_id) > -1){                     cb(user)                 }             })         }          this.onuserdisconnected = function(arrayofuserid,cb){             if(typeof arrayofuserid != 'object'){                 return console.error('onuserdisconnected 1st parameter not array');             }             socket.on('onuserdisconnected', function(user) {                 if(arrayofuserid.indexof(user.user_id) > -1){                     cb(user)                 }             })         } 

here socket.io server code:

 //some authentication here check , user if exists  socket.emit('onuserconnected', user) 

is emit user connected socket? , in client-side, fetch user logged in/out , check user_id if equal 1 of value in arrayofuserid return it?

note: know socket.io rooms, in application handle multiple tabs, , have dynamic namespace

does socket.io emit lot of processing power?

it's not clear mean here. socket.io, itself, uses tcp send websocket messages. not use lot of processing power, though if sending lot of messages lot of clients, can use cpu.

is emit user connected socket?

in general, should send clients information need. sending clients information clients limit scalability there lots , lots of updates going clients. every transmission received client consumes power (relevant battery powered devices) limiting transmissions clients too.

the efficient scheme have client tell server information wants , have server send info client , send when changes. more efficient having server sending info client , letting client sort through it.

and in client-side, fetch user logged in/out , check user_id if equal 1 of value in arrayofuserid return it?

same answer above. if can have server alert client when interested has happened, better.

note: know socket.io rooms, in application handle multiple tabs, , have dynamic namespace

you can use socket.io rooms fine dynamically created rooms. haven't described actual application, rooms excellent built-in way groups of users communicate or update each other , it's easy server manage communication using built-in features of rooms.