]> git.mdlowis.com Git - proto/atv.git/commitdiff
pass client to command handlers
authorMike Lowis <mike.lowis@gentex.com>
Mon, 15 Jan 2024 21:04:54 +0000 (16:04 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 15 Jan 2024 21:04:54 +0000 (16:04 -0500)
atv/lib/atv/server.rb
index.html

index bb5b2637f3316b11ce4c8c020566fc3bf93f832c..6bbc2a504c3ed4111c1a78af40e8fa0830cab221 100644 (file)
@@ -43,26 +43,26 @@ module ATV
 
     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
 
index 18b8354530d0049e8c4883aa5279b6913b6a4327..f6bc175e87ab0fefc2f1ea80d566303244699323 100644 (file)
 </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);
     }
 };