Last active
December 15, 2015 04:19
-
-
Save mcfiredrill/5200804 to your computer and use it in GitHub Desktop.
push metadata updates from liquidsoap to http stream in sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* redis pub/sub | |
* no support for redis in liquidsoap, could call a ruby script? | |
* osc? | |
* supported directly in liquidsoap | |
* unix socket | |
* would require local sinatra app to communicate with the outside world | |
* write to file, poll filesystem with fs-events gem | |
* would require local sinatra app to communicate with the outside world | |
Redis idea seems good. I'm already a little familiar with the technology from working with Resque. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adopted from https://github.com/gorsuch/sinatra-streaming-example/blob/master/worker.rb | |
require 'redis' | |
redis_url = ENV["REDISTOGO_URL"] || "redis://localhost:6379" | |
uri = URI.parse(redis_url) | |
r = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) | |
meta = ARGV[0] | |
puts "setting metadata..." | |
r.publish "metadata", meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source = on_metadata(pub_metadata, source) | |
def on_metadata(m) = | |
log("metadata changed: #{m}") | |
result = get_process_lines("./pub_metadata #{m}") | |
log("pub_metadata: #{result}") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var es = new EventSource('/metadata'); | |
es.onmessage = function(e) { $('#streamtitle').html(e.title) }; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/gorsuch/sinatra-streaming-example/blob/master/web.rb | |
require 'redis' | |
require 'sinatra' | |
configure do | |
redis_url = ENV["REDISTOGO_URL"] || "redis://localhost:6379" | |
uri = URI.parse(redis_url) | |
set :redis, Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) | |
end | |
get '/metadata' do | |
puts "connection made" | |
stream do |out| | |
settings.redis.subscribe 'metadata' do |on| | |
on.message do |channel, message| | |
out << "#{message}\n" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to be working so far. But I can only stream the events to one client at a time, it seems like. It seems to be very flaky, sometimes the connection just hangs and I don't see any data for a long time.