Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 52 lines (41 sloc) 0.902 kb
#!/usr/bin/env ruby
#
# realtime
#
# Sends now_playing to pusher to update web clients
$PROGRAM_NAME = 'play [realtime-daemon]'
require 'app/boot'
class Realtime
def initialize
@last = nil
end
def update
if @last != @last=current
Pusher['now_playing_updates'].trigger('update_now_playing', @last)
end
rescue Pusher::ConfigurationError
end
private
# The current JSON representation of Play that we send back.
#
# Returns a String, JSON-encoded.
def current
now_playing = Play::Player.now_playing
now_playing = now_playing.to_hash if now_playing
songs = Play::Queue.songs
Yajl.dump({
:now_playing => now_playing,
:songs => songs.map {|song| song.to_hash }
})
end
end
sleep 2
realtime = Realtime.new
while true
begin
sleep 1
realtime.update
rescue Exception => e
puts "An Exception: \n #{e}"
end
end
Jump to Line
Something went wrong with that request. Please try again.