javascript - socket.io emitting every second -


really quick question.

i'm creating synced streaming app emit current timecode of what's being played every second through socket.io , broadcast down other clients.

is wise? there drawbacks making same call every second, can make other calls @ same time?

p.s. i'm not making database calls or doing processing server-side.

with not many clients viewing videos should fine, experience small lags if number of users viewing starts big.

another approach keep track on server example can this

video loads autoplay or emit event start timer server-side

// client-side socket.emit('videoplaying',/* video data */); 


on server side start small timers based on socket ids

function timer(videoinformation){   this.currenttime=0;   this.startedat=+new date();   this.endedat=null;   this.title=videoinformation.title||'untitled';   this.interval=null;   this.play=function(){   var self=this;    this.interval=setinterval(function(){ self.currenttime=+new date(); },1000);   }   this.stop=function(){    if(this.interval!==null){ clearinterval(this.interval) }   }   //.. pause/end/reset .. } //server side var timetracker={}; // handling new videoplaying socket.on('videoplaying',function(videoinformation){  if(!timetracker.hasownproperty(socket.id)){   timetracker[socket.id]=[];  }  timetracker[socket.id].push(new timer(videoinformation)); }); 


in end add event listeners current video user viewing notify server timer has paused/stopped/click on specific video time etc..

hope helps, isn't working solution, more concept..


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -