diff --git a/features/support/data.rb b/features/support/data.rb index 605799a..07476ac 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -5,7 +5,9 @@ module FakeData jobs = [] 10.times do |i| jobs << {'id' => "cuke-#{i}", - 'name' => "Cucumber Job #{i}"} + 'name' => "Cucumber Job #{i}", + 'end_time' => 30, + 'start_time' => 20} end jobs end diff --git a/lib/saucetv/app.rb b/lib/saucetv/app.rb index 2786e08..d44a6ae 100644 --- a/lib/saucetv/app.rb +++ b/lib/saucetv/app.rb @@ -34,18 +34,53 @@ module SauceTV redirect to('/watch') end + get '/next/after/:id' do |id| + unless authenticated? + redirect to('/login') + end + + api = api_for_session + jobs = [] + begin + jobs =api.recent_jobs + rescue SauceTV::InvalidUserCredentials + redirect to('/login?invalid=true') + end + + if jobs.empty? + redirect to('/watch') + end + + previous = nil + jobs.each do |job| + break if id == job['id'] + previous = job + end + + unless previous.nil? + redirect to("/watch/#{previous['id']}") + end + redirect to('/watch') + end + get '/watch/:id' do |id| unless authenticated? redirect to('/login') end api = api_for_session - info = api.info_for(id) + begin + info = api.info_for(id) + rescue SauceTV::InvalidUserCredentials + redirect to('/login?invalid=true') + end haml :player, :locals => { - :session => session[:username], + :username => session[:username], :id => id, - :info => info + :delay => info['end_time'] - info['start_time'], + :info => info, + :token => api.auth_token_for(id) } end diff --git a/lib/saucetv/views/player.haml b/lib/saucetv/views/player.haml index 17386da..40d0c4b 100644 --- a/lib/saucetv/views/player.haml +++ b/lib/saucetv/views/player.haml @@ -1,7 +1,15 @@ %html %head + %meta{'http-equiv' => 'refresh', + :content => "#{delay};url=/next/after/#{id}"} + %script{:type => 'text/javascript', + :src => '/flowplayer/flowplayer-3.2.11.min.js'} %title - SauceLabs.tv + SauceLabs.tv - #{info['name']} %body - Now watching: #{info['name']} + Now watching: #{info['name']} (#{delay}s) + %script{:type => 'text/javascript', + :src => "http://saucelabs.com/video-embed/#{id}.js?auth=#{token}"} + %script{:type => 'text/javascript'} + $f(0).play(); diff --git a/lib/saucetv/views/watch.haml b/lib/saucetv/views/watch.haml index fa71b21..cfaa175 100644 --- a/lib/saucetv/views/watch.haml +++ b/lib/saucetv/views/watch.haml @@ -3,17 +3,16 @@ %title SauceLabs.tv %body - Welcome #{username} - + %div{:style => 'float: right; clear: all; font-weight: bold'} + Welcome #{username} - unless jobs.empty? %a{:href => "/watch/#{jobs[-1]['id']}"} Auto-Play - %ul#jobs + %ol#jobs - jobs.compact.each do |job| %li.job{:id => "job_#{job['id']}"} - %a{:href => "https://saucelabs.com/jobs/#{job['id']}"} + %a{:href => "/watch/#{job['id']}"} = job['name'] - ·