--- /dev/null
+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
--- /dev/null
+<!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>
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