Skip to content

Commit

Permalink
switched to progress bar, updated new version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
antulik committed Mar 15, 2015
1 parent 6fa8eaa commit 930a701
Show file tree
Hide file tree
Showing 47 changed files with 228 additions and 12,784 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
/tmp
/release
/packaging/vendor
/db/*.pstore
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ gem 'sprockets-rails'
gem 'airplay', '>= 1.0.3'

gem 'celluloid'
gem 'httparty'

group :development, :test do
#assets
source 'https://rails-assets.org' do
gem 'rails-assets-messenger'
gem 'rails-assets-backbone'
gem 'rails-assets-bootstrap'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
Expand All @@ -34,6 +37,7 @@ group :development, :test do
gem 'coffee-rails', '~> 4.1.0'

gem 'jquery-rails'
gem "non-stupid-digest-assets"

#dev
gem 'bundler', '>= 1.8.4', '< 2.0'
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ GEM
http_parser.rb (~> 0.6.0)
http-form_data (1.0.0)
http_parser.rb (0.6.0)
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.7.0)
jquery-rails (4.0.3)
rails-dom-testing (~> 1.0)
Expand All @@ -88,6 +91,7 @@ GEM
mini_portile (0.6.2)
minitest (5.5.1)
multi_json (1.11.0)
multi_xml (0.5.5)
net-http-digest_auth (1.2.1)
net-ptth (0.0.17)
celluloid-io (>= 0.15.0)
Expand All @@ -96,16 +100,22 @@ GEM
nio4r (1.1.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
non-stupid-digest-assets (1.0.4)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.0)
rack-test (0.6.3)
rack (>= 1.0)
rails-assets-backbone (1.1.2)
rails-assets-underscore (>= 1.5.0)
rails-assets-bootstrap (3.3.2)
rails-assets-jquery (>= 1.9.1)
rails-assets-jquery (2.1.3)
rails-assets-messenger (1.4.1)
rails-assets-jquery
rails-assets-underscore (1.8.2)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
Expand Down Expand Up @@ -184,8 +194,12 @@ DEPENDENCIES
byebug
celluloid
coffee-rails (~> 4.1.0)
httparty
jquery-rails
non-stupid-digest-assets
pry
rails-assets-backbone!
rails-assets-bootstrap!
rails-assets-messenger!
railties
sass-rails (~> 5.0)
Expand Down
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ end

# For Bundler.with_clean_env
require 'bundler/setup'
require_relative 'lib/web_airplay'

PACKAGE_NAME = "webairplay"
VERSION = "0.5.0"
VERSION = WebAirplay::VERSION
TRAVELING_RUBY_VERSION = "20150210-2.2.0"
# SQLITE3_VERSION = "1.3.9" # Must match Gemfile

Expand Down Expand Up @@ -93,7 +94,8 @@ def build_osx_app

sh('/usr/local/bin/platypus',
'-a WebAirplay',
'-o', 'Text Window',
'-o', 'Progress Bar',
# '-o', 'Text Window',
'-p', '/bin/bash',
'-V', VERSION,
'-u', 'Anton Katunin',
Expand Down
16 changes: 14 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@
//= require jquery_ujs
//1= require turbolinks

//= require underscore
//= require backbone

//= require messenger
//= require bootstrap

//= require youtube-video

//= require_tree .
//= require m-player/m-player

//= require player
//= require_self

Messenger.options = {
extraClasses: 'messenger-fixed messenger-on-top',
theme: 'future'
}
};

$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
2 changes: 1 addition & 1 deletion app/assets/javascripts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Player = Backbone.Model.extend({
next: function() {},

url: function() {
return '/backbone_info'
return '/player/backbone_info'
}
});

Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
*= require_tree .
*= require messenger
*= require bootstrap
*= require m-player/m-player
*= require_self
*/

body {
padding: 10px;
margin-bottom: 100px;
}

#player {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 10px;
background-color: rgb(60, 60, 60);
}
65 changes: 15 additions & 50 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ class HomeController < ApplicationController
BLANK_GIF = Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

def show
begin
@device_names = Airplay.devices.to_a.map(&:name)
rescue Airplay::Browser::NoDevicesFound
@device_names = []
@device_names = Mediabox.instance.devices.map(&:name)
end

def refresh_devices
Mediabox.instance.browse
redirect_to root_path
end

def version_check
@release = Github.latest_release

if WebAirplay::RELEASE_ID == @release.id
head :ok
else
render
end
end

Expand All @@ -28,52 +39,6 @@ def img_play
render text: BLANK_GIF, type: 'image/gif'
end

def backbone_info
if Mediabox.instance.player && (!Mediabox.instance.player.alive? || Mediabox.instance.player.stopped?)
Mediabox.instance.player = nil
Airplay.clear_browser
end

info = if Mediabox.instance.player
Mediabox.instance.player.info.info
else
{}
end

# info
#
# {"duration":134.97666931152344,
# "loadedTimeRanges":[
# {"duration":7.535599546,"start":32.422733787}
# ],
# "playbackBufferEmpty":true,
# "playbackBufferFull":false,
# "playbackLikelyToKeepUp":true,
# "position":32.92290115356445,
# "rate":1.0,
# "readyToPlay":true,
# "seekableTimeRanges":[
# {"duration":134.97666666666666,"start":0.0}
# ]
# }

play_state = if Mediabox.instance.player && Mediabox.instance.player.playing?
'playing'
elsif Mediabox.instance.player && Mediabox.instance.player.stopped?
'stopped'
else
'paused'
end

result = {
:_position => info['position'].to_i,
:_duration => info['duration'].to_i,
:_playState => play_state
}

render json: result.to_json
end

private

def device_names
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,51 @@ def pause
head :ok
end

def backbone_info
if Mediabox.instance.player && (!Mediabox.instance.player.alive? || Mediabox.instance.player.stopped?)
Mediabox.instance.player = nil
Airplay.clear_browser
end

info = if Mediabox.instance.player
Mediabox.instance.player.info.info
else
{}
end

# info
#
# {"duration":134.97666931152344,
# "loadedTimeRanges":[
# {"duration":7.535599546,"start":32.422733787}
# ],
# "playbackBufferEmpty":true,
# "playbackBufferFull":false,
# "playbackLikelyToKeepUp":true,
# "position":32.92290115356445,
# "rate":1.0,
# "readyToPlay":true,
# "seekableTimeRanges":[
# {"duration":134.97666666666666,"start":0.0}
# ]
# }

play_state = if Mediabox.instance.player && Mediabox.instance.player.playing?
'playing'
elsif Mediabox.instance.player && Mediabox.instance.player.stopped?
'stopped'
else
'paused'
end

result = {
:_position => info['position'].to_i,
:_duration => info['duration'].to_i,
:_playState => play_state
}

render json: result.to_json
end


end
7 changes: 6 additions & 1 deletion app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ def create
end
end

end
def clear
Video.all.clear
Video.save_to_disk
redirect_to root_path
end

end
16 changes: 16 additions & 0 deletions app/models/github.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Github

def self.releases
response = HTTParty.get('https://api.github.com/repos/antulik/web-airplay/releases')
response.parsed_response.map(&Release.method(:new))
end

def self.latest_release
releases.sort_by { |r| r['id'] }.last
end

class Release < OpenStruct

end

end
21 changes: 12 additions & 9 deletions app/models/mediabox.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
class Mediabox
include Singleton

attr_accessor :player
attr_accessor :player, :devices


def initialize
browse
end

def browse
Airplay.browse
self.devices = Airplay.devices.to_a.dup
rescue Airplay::Browser::NoDevicesFound
self.devices = []
end

def default_device_index
Expand All @@ -16,22 +25,16 @@ def default_device_index= device_index

def play url, device_index = default_device_index
puts 7.chr
url = parse_url url

if device_index
device_index = device_index.to_i
device = Airplay.devices.to_a[device_index]
else
device = Airplay.devices.to_a.last
end
url = parse_url url
device = devices[device_index.to_i]

if url
play_on_device device, url
end
end

def play_on_device device, url

if player && !player.alive?
self.player = nil
end
Expand Down
Loading

0 comments on commit 930a701

Please sign in to comment.