From d9443389dbebecb458d3eca85ec2bc6b9d94573a Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sat, 7 Dec 2013 19:42:12 +0000 Subject: [PATCH] Send time data back to client. --- mpd_client.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mpd_client.rb b/mpd_client.rb index 2ede6f8..ddfb61e 100644 --- a/mpd_client.rb +++ b/mpd_client.rb @@ -38,9 +38,15 @@ class MPDClient < Sinatra::Base settings.connections.each { |out| out << "data: #{response}\n\n" } end + def self.send_time(elapsed, total) + response = JSON({ type: 'time', data: { elapsed: elapsed, total: total } }) + settings.connections.each { |out| out << "data: #{response}\n\n" } + end + MPDConnection.mpd.on(:song) { |song| send_status } MPDConnection.mpd.on(:state) { |state| send_status } MPDConnection.mpd.on(:playlist) { |playlist| send_queue } + MPDConnection.mpd.on(:time) { |elapsed, total| send_time(elapsed, total) } namespace '/api' do