Really quick question.
I'm creating a synced streaming app so I would like to emit the current timecode of what's being played every second through socket.io and broadcast it down to other clients.
Is this wise? Are there any drawbacks to making the same call every second, can I make other calls at the same time?
PS I'm not making any database calls or doing any processing server-side.
with not to many clients viewing videos it should be fine, but eventually you will experience small lags if the number of users viewing starts to get big.
Another approach is to keep track on server for example you can do this
Video loads with autoplay or emit an event to start a timer server-side
// from client-side
socket.emit('videoplaying',/* some video data */);
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)); });
Hope it helps, this isn't a working solution, its more a concept..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.