def on_message(client, cmd)
cmd = JSON.parse(cmd)
- send("on_#{cmd["cmd"]}".to_sym, cmd)
+ send("on_#{cmd["cmd"]}".to_sym, client, cmd)
end
- def on_skip(data)
+ def on_skip(client, data)
puts "skip"
end
- def on_play(data)
+ def on_play(client, data)
puts "play"
end
- def on_pause(data)
+ def on_pause(client, data)
puts "pause"
end
- def on_chan_next(data)
+ def on_chan_next(client, data)
puts "chan_next"
end
- def on_chan_prev(data)
+ def on_chan_prev(client, data)
puts "chan_prev"
end
</video>
<script>
-let now_playing = {};
-
-const secondsSinceMidnight = ()=>{
- const now = new Date();
- const midnight = new Date(
- now.getFullYear(),
- now.getMonth(),
- now.getDate(),
- 0,0,0);
- return (now.getTime() - midnight.getTime()) / 1000;
-};
-
-const updatePlayer = ()=>{
- const duration = now_playing["curr"]["duration"];
- const since_mn = secondsSinceMidnight();
- const end_time = now_playing["start_time"] + duration;
- const offset = duration - (end_time - since_mn);
- if (offset > 0 && offset < duration)
+const updatePlayer = (data)=>{
+ console.log(data["curr"]);
+ console.log(data["curr"]["duration"])
+ const duration = data["curr"]["duration"];
+ const elapsed = data["time"]
+ if (elapsed > 0 && elapsed < duration)
{
- Video.src = now_playing["curr"]["path"] + "#t=" + Math.floor(offset);
+ Video.src = data["curr"]["path"] + "#t=" + Math.floor(elapsed);
}
};
const Cmd = {
play: (data)=>{
- now_playing = data;
- updatePlayer();
+ console.log(data);
+ updatePlayer(data);
}
};