-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrealtime
executable file
·52 lines (41 loc) · 902 Bytes
/
realtime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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