]> git.mdlowis.com Git - proto/atv.git/commitdiff
added logic to install website files automatically on server start as well as handle...
authorMike Lowis <mike.lowis@gentex.com>
Mon, 15 Jan 2024 21:03:02 +0000 (16:03 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 15 Jan 2024 21:03:02 +0000 (16:03 -0500)
atv/assets/client.js [new file with mode: 0644]
atv/assets/control.html
atv/bin/atv
atv/lib/atv/server.rb

diff --git a/atv/assets/client.js b/atv/assets/client.js
new file mode 100644 (file)
index 0000000..ce9bc18
--- /dev/null
@@ -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(onmsg);
+        };
+    };
+
+    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
index 9747101ee43d966243c6b21c8aad928b04712336..4a8f6ef745f766c4de589e43912f68f8b074aceb 100644 (file)
@@ -24,7 +24,6 @@
 <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>
 (()=>{
index 9eba39078a5a263722bf95663f11e52c8abff7f7..008d8c82eee4cb1491a99d71177e6bfabe836fd9 100755 (executable)
@@ -4,13 +4,23 @@ require 'atv/database'
 require 'atv/channel'
 require 'atv/player'
 require 'atv/server'
+require 'fileutils'
 
-db = ATV::Database.new(ENV["ATV_ROOT"] || "/var/www/atv")
+ATV_ROOT = (ENV["ATV_ROOT"] || "/var/www/atv")
+ASSET_DIR = File.join(File.dirname(__FILE__), "../assets")
+
+# Update website files first
+Dir.glob("#{ASSET_DIR}/**/*.*").each do |path|
+  file = File.basename(path)
+  puts "#{ATV_ROOT}/#{file}"
+  FileUtils.cp(path, "#{ATV_ROOT}/#{file}")
+end
+
+# Then run the server
+db = ATV::Database.new(ATV_ROOT)
 channels = [
   ATV::Channel.new('Everything', db,
     ["Movies", "Shorts", "Shows"])
 ]
 player = ATV::Player.new(db, channels)
 ATV::Server.start(player)
-#server = ATV::Server.new(player)
-#server.start
index 8c5036922601e767ce7bd8831953071b8d6e0288..bb5b2637f3316b11ce4c8c020566fc3bf93f832c 100644 (file)
@@ -26,10 +26,15 @@ module ATV
       Iodine.publish(:atv, JSON.dump(obj))
     end
 
+    def client_send(client, obj)
+      puts "To #{client} #{JSON.dump(obj)}"
+      client.write JSON.dump(obj)
+    end
+
     def on_open(client)
       puts "connect: #{client}"
       client.subscribe :atv
-      publish(@@player.state.merge({"cmd" => "play"}))
+      client_send(client, @@player.state.merge({"cmd" => "play"}))
     end
 
     def on_close(client)
@@ -38,13 +43,33 @@ module ATV
 
     def on_message(client, cmd)
       cmd = JSON.parse(cmd)
-      Cmds[cmd["cmd"]].call(cmd["data"])
+      send("on_#{cmd["cmd"]}".to_sym, cmd)
+    end
+
+    def on_skip(data)
+      puts "skip"
+    end
+
+    def on_play(data)
+      puts "play"
     end
 
-    def send(client, data)
-      client.write JSON.dump(data)
+    def on_pause(data)
+      puts "pause"
     end
 
+    def on_chan_next(data)
+      puts "chan_next"
+    end
+
+    def on_chan_prev(data)
+      puts "chan_prev"
+    end
+
+#    def send(client, data)
+#      client.write JSON.dump(data)
+#    end
+#
 #    Cmds = {
 #      "skip" => lambda do |data|
 #        cfg = $channels[$channel]