]> git.mdlowis.com Git - proto/atv.git/commitdiff
added client.js for shared code
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 24 Dec 2023 03:44:45 +0000 (22:44 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 24 Dec 2023 03:44:45 +0000 (22:44 -0500)
client.js [new file with mode: 0644]
control.html [new file with mode: 0644]
serve-videos

diff --git a/client.js b/client.js
new file mode 100644 (file)
index 0000000..d6589d5
--- /dev/null
+++ b/client.js
@@ -0,0 +1,54 @@
+const Client = ((self = {})=>{
+    let ws = null;
+
+    self.connect = (onmsg)=>{
+        self.onmessage = onmsg;
+
+        ws = new WebSocket(
+            "ws://" + window.location.host + ":3000");
+
+        ws.onmessage = (event)=>{
+            self.onmessage(JSON.parse(event.data));
+        };
+
+        ws.onclose = ()=>{
+            self.connect();
+        };
+    };
+
+    const send = (cmd, data = {})=>{
+        const blob = { cmd: cmd, data: data};
+        console.log(blob);
+        ws.send(JSON.stringify(blob));
+    };
+
+    self.skip = (data)=>{
+        send("skip");
+    };
+
+    self.play = (data)=>{
+        send("play");
+    };
+
+    self.pause = (data)=>{
+        send("pause");
+    };
+
+    self.chan_next = (data)=>{
+        send("chan_next");
+    };
+
+    self.chan_prev = (data)=>{
+        send("chan_prev");
+    };
+
+    self.play_next = (path)=>{
+
+    };
+
+    self.play_now = (path)=>{
+
+    };
+
+    return self;
+})();
\ No newline at end of file
diff --git a/control.html b/control.html
new file mode 100644 (file)
index 0000000..9747101
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html dir="ltr" lang="en-US">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+  <meta name="viewport" content="width=device-width,initial-scale=1">
+  <style>
+    html, body {
+      margin: 0;
+      padding: 0;
+      width: 100%;
+      height: 100%;
+      max-height: 100%;
+      background-color: #000;
+      overflow: hidden;
+    }
+  </style>
+</head>
+<body>
+
+
+<input type="button" value="Skip" onclick="javscript:Client.skip()"/>
+<input type="button" value="Play" onclick="javscript:Client.play()"/>
+<input type="button" value="Pause" onclick="javscript:Client.pause()"/>
+<input type="button" value="Chan +" onclick="javscript:Client.chan_next()"/>
+<input type="button" value="Chan -" onclick="javscript:Client.chan_prev()"/>
+
+
+<script type="text/javascript" src="client.js"></script>
+<script>
+(()=>{
+    Client.connect(()=>{});
+})();
+</script>
+</body>
+</html>
index 9e01951e015c88aacccd1976e073011d0fe3f230..e576a09d3947d4c6d9f5c83077f00c1b2bdc6b84 100755 (executable)
@@ -85,14 +85,51 @@ module ATV
     puts "disconnect: #{client}"
   end
 
-  def on_message(client, data)
-    # nothing to do, we are stream only
+  def on_message(client, cmd)
+    cmd = JSON.parse(cmd)
+    Cmds[cmd["cmd"]].call(cmd["data"])
   end
 
   def send(client, data)
     client.write JSON.dump(data)
   end
 
+  Cmds = {
+    "skip" => lambda do |data|
+      cfg = $channels[$channel]
+      cfg[:play][:start_time] = secs_since_midnight()
+      cfg[:play][:curr] = cfg[:play][:next]
+      cfg[:play][:next] = next_show($channel)
+      update_program()
+    end,
+
+    "play" => lambda do |data|
+      pp data
+    end,
+
+    "pause" => lambda do |data|
+      pp data
+    end,
+
+    "chan_prev" => lambda do |data|
+      $channel -= 1
+      if $channel < 0
+        $channel = $channels.length - 1
+      end
+      puts $channel
+      update_program()
+    end,
+
+    "chan_next" => lambda do |data|
+      $channel += 1
+      if $channel >= $channels.length
+        $channel = 0
+      end
+      puts $channel
+      update_program()
+    end,
+  }
+
   extend self
 end