From 2919fd94be1f1cb87da1f231c9edae9f22a1807a Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Mon, 15 Jan 2024 16:03:02 -0500 Subject: [PATCH] added logic to install website files automatically on server start as well as handle incoming commands using ruby send() logic --- atv/assets/client.js | 54 +++++++++++++++++++++++++++++++++++++++++ atv/assets/control.html | 1 - atv/bin/atv | 16 +++++++++--- atv/lib/atv/server.rb | 33 ++++++++++++++++++++++--- 4 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 atv/assets/client.js diff --git a/atv/assets/client.js b/atv/assets/client.js new file mode 100644 index 0000000..ce9bc18 --- /dev/null +++ b/atv/assets/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(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 diff --git a/atv/assets/control.html b/atv/assets/control.html index 9747101..4a8f6ef 100644 --- a/atv/assets/control.html +++ b/atv/assets/control.html @@ -24,7 +24,6 @@ -