jam-cloud/web/app/controllers/api_icecast_controller.rb

74 lines
1.6 KiB
Ruby

class ApiIcecastController < ApiController
before_filter :local_only
before_filter :parse_mount
# each request will have this in it, if it's icecast.
#user-agent = Icecast 2.3.3
def mount_add
mount = IcecastMount.find(@mount_id)
mount.source_up
render text: '', :status => :ok
end
def mount_remove
mount = IcecastMount.find(@mount_id)
mount.source_down
render text: '', :status => :ok
end
def listener_add
client = params[:client] # icecast internal id, e.g. 149
user = params[:user] # basic auth in the request sent to icecast
pass = params[:pass] # basic auth in the request sent to icecast
remote_ip = params[:ip]
remote_user_agent = params[:agent]
mount = IcecastMount.find(@mount_id)
mount.listener_add
render text: '', :status => :ok
end
def listener_remove
client = params[:client] # you can use this to correlate the listener_add...
user = params[:user] # or user/pass (icecast is storing these as well and reflects them back)
pass = params[:pass]
duration = params[:duration] # seconds connected to the listen stream
mount = IcecastMount.find(@mount_id)
mount.listener_remove
render text: '', :status => :ok
end
protected
def local_only
request.local?
end
def parse_mount()
mount = params[:mount]
# Example A
# browser: http://icecast/a
# mount: /a
#
# Example B
# browser: http://icecast/a?dog=legs&mump
# mount: /a?dog=legs&mump
# browser: http://icecast/a#bleh
# mount: /a
uri = URI(mount)
@mount_id = uri.path
@mount_params = Rack::Utils.parse_query(uri.query)
end
end