From c558e3dc86e4461d0a511405e996b3bbcf0b877d Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Tue, 20 Jun 2017 13:35:06 +0200 Subject: [PATCH] adding sstop updates --- index.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index f8e5062..5c986ac 100755 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ io.on("connection", (socket)=>{ activeFile = data.file; player.loadFile(__dirname + "/files/" + data.file, ()=>{ player.play(()=>{ + Update.start(); socket.emit("playing", {file: data.file}); }); }); @@ -22,23 +23,32 @@ io.on("connection", (socket)=>{ socket.on("stop", (data)=>{ player.stop(()=>{ + Update.stop(); io.emit("stopped"); }); }); }); -setInterval(()=>{ - var start - var update_infos = {}; - player.getTime((t)=>{ - player.getState((playing)=>{ - update_infos.file = activeFile; - update_infos.time = t; - update_infos.is_playing = playing; - //update_infos. - io.emit("update", update_infos); - }) - }); -}, 1000/25) +class Update { + static start() { + Update.interv = setInterval(()=>{ + var start + var update_infos = {}; + player.getTime((t)=>{ + player.getState((playing)=>{ + update_infos.file = activeFile; + update_infos.time = t; + update_infos.is_playing = playing; + //update_infos. + io.emit("update", update_infos); + }) + }); + }, 1000/25) + } + + static stop() { + clearInterval(Update.interv); + } +} http.listen(5000); \ No newline at end of file