From: Michael D. Lowis Date: Mon, 8 Jan 2024 03:50:33 +0000 (-0500) Subject: add assets and almost completed reorg. weird bug when transitioning to new video... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=eb4628cf37a40d13347576f46570b3698a293d52;p=proto%2Fatv.git add assets and almost completed reorg. weird bug when transitioning to new video though O_o --- diff --git a/atv/assets/control.html b/atv/assets/control.html new file mode 100644 index 0000000..9747101 --- /dev/null +++ b/atv/assets/control.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/atv/assets/index.html b/atv/assets/index.html new file mode 100644 index 0000000..f6bc175 --- /dev/null +++ b/atv/assets/index.html @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/atv/bin/atv b/atv/bin/atv index f7a63f2..3a04355 100755 --- a/atv/bin/atv +++ b/atv/bin/atv @@ -11,5 +11,6 @@ channels = [ ["Movies", "Shorts", "Shows"]) ] player = ATV::Player.new(db, channels) -server = ATV::Server.new(player) -server.start +ATV::Server.start(player) +#server = ATV::Server.new(player) +#server.start diff --git a/atv/lib/atv/channel.rb b/atv/lib/atv/channel.rb index 3c63716..2cbb4c6 100644 --- a/atv/lib/atv/channel.rb +++ b/atv/lib/atv/channel.rb @@ -8,13 +8,14 @@ module ATV @items = selectors.map do |sel| files.select {|f| f["path"].start_with? sel } end.flatten.shuffle + @time = @items[@index]["duration"] - 10 end def update(playing) @time += 1 if playing item = @items[@index] if @time >= item["duration"] then - next() + next_vid() pp @items[@index] true else @@ -22,12 +23,22 @@ module ATV end end - def next() - @time = 0 + def next_vid() @index += 1 if @index >= @items.length @index = 0 end + @time = 0 + @time = @items[@index]["duration"] - 10 + end + + def state() + next_index = ((@index+1) >= @items.length ? 0 : (@index+1)) + { + "time" => @time, + "curr" => @items[@index], + "next" => @items[next_index] + } end end end diff --git a/atv/lib/atv/player.rb b/atv/lib/atv/player.rb index 1709e1a..d1de7f0 100644 --- a/atv/lib/atv/player.rb +++ b/atv/lib/atv/player.rb @@ -12,6 +12,8 @@ module ATV @channels.each do |c| updated ||= c.update(@playing) end +# puts updated + updated end def play() @@ -39,5 +41,9 @@ module ATV @channel = @channels.length - 1 end end + + def state() + @channels[@channel].state + end end end diff --git a/atv/lib/atv/server.rb b/atv/lib/atv/server.rb index e81b8a8..8c50369 100644 --- a/atv/lib/atv/server.rb +++ b/atv/lib/atv/server.rb @@ -1,24 +1,86 @@ require 'iodine' module ATV - class Server + module Server APP = Proc.new do |env| if env['rack.upgrade?'.freeze] == :websocket - env['rack.upgrade'.freeze] = ATV + env['rack.upgrade'.freeze] = ATV::Server [0,{}, []] # It's possible to set cookies for the response. end end - def initialize(player) - @player = player - end - - def start() + def start(player) + @@player = player Iodine.listen(service: :http, handler: APP) Iodine.run_every(1000) do - @player.update + if player.update + publish(@@player.state.merge({"cmd" => "play"})) + end end + Iodine.threads = 1 Iodine.start end + + def publish(obj) + puts JSON.dump(obj) + Iodine.publish(:atv, JSON.dump(obj)) + end + + def on_open(client) + puts "connect: #{client}" + client.subscribe :atv + publish(@@player.state.merge({"cmd" => "play"})) + end + + def on_close(client) + puts "disconnect: #{client}" + end + + 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 end