]> git.mdlowis.com Git - proto/atv.git/commitdiff
first pass at websocket based stream
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 22 Dec 2023 04:36:51 +0000 (23:36 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 22 Dec 2023 04:36:51 +0000 (23:36 -0500)
.gitignore
TODO.md [new file with mode: 0644]
index.html
serve-videos

index 94a2dd146a22340832c88013e9fe92663bb9f2cc..80976e149b8c9b6eb4ad41ec49038ad873db69c3 100644 (file)
@@ -1 +1,6 @@
-*.json
\ No newline at end of file
+*.json
+Christmas/
+Pictures/
+Movies/
+Shorts/
+Shows/
diff --git a/TODO.md b/TODO.md
new file mode 100644 (file)
index 0000000..00b5d12
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,15 @@
+# Commands
+
+* skip
+* play
+* pause
+* channel next/prev
+* play next
+* play now
+
+# Features
+
+* Show the play queue
+* list connected clients
+* show photos
+* algorithm for picking movies
\ No newline at end of file
index dfc85f9707a996a1070e2eb8dd1a28a2e8021d54..18b8354530d0049e8c4883aa5279b6913b6a4327 100644 (file)
@@ -20,6 +20,7 @@
 </video>
 
 <script>
+let now_playing = {};
 
 const secondsSinceMidnight = ()=>{
     const now = new Date();
@@ -31,24 +32,28 @@ const secondsSinceMidnight = ()=>{
     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)
+    {
+        Video.src = now_playing["curr"]["path"] + "#t=" + Math.floor(offset);
+    }
+};
+
 const Cmd = {
     play: (data)=>{
-        console.log(data);
-        const duration = data["curr"]["duration"];
-        const since_mn = secondsSinceMidnight();
-        const end_time = data["start_time"] + duration;
-        const offset   = duration - (end_time - since_mn);
-        console.log(offset);
-        if (offset > 0 && offset < duration)
-        {
-            Video.src = data["curr"]["path"] + "#t=" + Math.floor(offset);
-            console.log(Video.src);
-        }
+        now_playing = data;
+        updatePlayer();
     }
 };
 
 const connect = ()=>{
-    let ws = new WebSocket("ws://" + window.location.host);
+    let ws = new WebSocket(
+        "ws://" + window.location.host + ":3000");
+
     ws.onmessage = (event)=>{
         const msg = JSON.parse(event.data);
         Cmd[msg.cmd](msg);
@@ -59,8 +64,10 @@ const connect = ()=>{
     };
 };
 
+Video.addEventListener("ended", updatePlayer);
+document.addEventListener("visibilitychange", updatePlayer);
 
 (()=>{ connect(); })();
 </script>
 
-</body></html>
\ No newline at end of file
+</body></html>
index f05f097e8c56f50a89cc7589a872a941e24a2a6d..9e01951e015c88aacccd1976e073011d0fe3f230 100755 (executable)
@@ -9,12 +9,12 @@ $db = JSON.parse(File.read("index.json"))
 $now_playing = nil
 $channel = 0
 $channels = [
-  { include: ["Christmas"] },
   { include: ["Movies", "Shorts", "Shows"] },
   { include: ["Movies"] },
   { include: ["Shorts"] },
   { include: ["Shows"] },
   { include: ["Pictures"] },
+  { include: ["Christmas"] },
 ]
 
 def secs_since_midnight()