class Rairtame::Client
Constants
- RECEIVER_PORT
- STREAMER_CMDS_PORT
Public Class Methods
new(opts={})
click to toggle source
# File lib/rairtame/client.rb, line 38 def initialize(opts={}) @config = Rairtame::Config.new(opts) @verbose = opts[:verbose] @streamer_host = opts[:streamer_host] || 'localhost' @streamer_uri = "http://#{@streamer_host}:#{STREAMER_CMDS_PORT}/" @json_rpc_client = Jsonrpctcp::Client.new(@streamer_host, STREAMER_CMDS_PORT) end
Public Instance Methods
audio=(v)
click to toggle source
# File lib/rairtame/client.rb, line 150 def audio=(v) # TODO: Read av flags first and keep the video flag value = case v when "on" then "3" when "off" then "1" end rpc_call(:setStreamerSettings, 'av_flags', value) end
audio_jitterbuffer=(v)
click to toggle source
unused
# File lib/rairtame/client.rb, line 171 def audio_jitterbuffer=(v) warn "Not implemented" nil end
buffer=(v)
click to toggle source
# File lib/rairtame/client.rb, line 142 def buffer=(v) rpc_call(:setStreamerSettings, 'buffer', v.to_s) end
close_streamer()
click to toggle source
# File lib/rairtame/client.rb, line 81 def close_streamer rpc_call(:closeStreamer) end
connect(host)
click to toggle source
# File lib/rairtame/client.rb, line 71 def connect(host) ip = resolve(host) rpc_call(:connect, ip, RECEIVER_PORT) end
disconnect(host)
click to toggle source
# File lib/rairtame/client.rb, line 76 def disconnect(host) ip = resolve(host) rpc_call(:disconnect, ip, RECEIVER_PORT) end
framerate=(v)
click to toggle source
# File lib/rairtame/client.rb, line 134 def framerate=(v) rpc_call(:setStreamerSettings, 'framerate', v.to_s) end
init_streamer()
click to toggle source
# File lib/rairtame/client.rb, line 67 def init_streamer rpc_call(:initStreamer) end
jitterbuffer_delay=(v)
click to toggle source
unknown
# File lib/rairtame/client.rb, line 177 def jitterbuffer_delay=(v) rpc_call(:setStreamerSettings, 'jb_delay', v.to_s) end
mode=(v)
click to toggle source
# File lib/rairtame/client.rb, line 146 def mode=(v) rpc_call(:setStreamerSettings, 'streaming_mode', v) end
pretty_status()
click to toggle source
# File lib/rairtame/client.rb, line 90 def pretty_status puts puts "AIRTAME status:" puts "---------------" state = rpc_call(:getState)['result'] if state['state'] == 'not initialized' puts "Not initialized" elsif state['current_mode'] mode_str = case state['current_mode'] when 0 then "video" when 1 then "work" when 2 then "present" when 3 then "manual" else "unknown" end fluent = state['remote_settings']['video_jb_flags'].to_i == 1 ? "yes" : "no" reliable = state['reliable_transport'].to_i == 1 ? "yes" : "no" buffer = state['remote_settings']['buffer_period'] puts "Mode: #{mode_str}" puts "FPS: #{state['video_fps']}" puts "Reliability: #{reliable}" puts "Fluent playback: #{fluent}" puts "Buffer: #{buffer}ms" puts "Clients:" puts " -- No clients connected" if state['clients'].empty? state['clients'].each do |client| c = client['channel'] str = "#{c['IP']}: " str << "Sent #{(c['bytes_sent'] / 1024.0 / 1024.0).round(2)} MB. " str << "Recv: #{(c['bytes_received'] / 1024.0).round(2)} KB. " str << "Packet loss: #{c['packet_loss'].to_f.round(2)}. " str << "Avg latency: #{c['avg_latency']}" puts " -- #{str}" end state else puts "Unkown response" end puts puts "(run with -v to see the raw response)" state end
Also aliased as: pretty_state
quality=(v)
click to toggle source
# File lib/rairtame/client.rb, line 138 def quality=(v) rpc_call(:setStreamerSettings, 'quality', v.to_s) end
reliable_transport=(v)
click to toggle source
# File lib/rairtame/client.rb, line 181 def reliable_transport=(v) rpc_call(:setStreamerSettings, 'reliable_transport', on_off_to_true_false(v)) end
resolution=(v)
click to toggle source
# File lib/rairtame/client.rb, line 186 def resolution=(v) rpc_call(:setStreamerSettings, 'encode_resolution', v) end
rpc_call(method, *params)
click to toggle source
# File lib/rairtame/client.rb, line 47 def rpc_call(method, *params) begin log_command(method, params) r = @json_rpc_client[method.to_s, *params] log_response(r) return r rescue Jsonrpctcp::RPCException raise $! rescue Jsonrpctcp::RPCError log_response($!.source_object) raise $! rescue StandardError msg = "Cannot connect to streamer: is it running?: #{$!.message}" raise ClientException.new(msg) rescue Exception msg = "An error occurred while talking to the streamer: #{$!.message}" raise ClientException.new(msg) end end
status()
click to toggle source
# File lib/rairtame/client.rb, line 85 def status rpc_call(:getState) end
Also aliased as: state
video=(v)
click to toggle source
# File lib/rairtame/client.rb, line 160 def video=(v) # TODO: Read av flags first and keep the audio rpc_call(:setStreamerSettings, 'av_flags', on_off_to_1_0(v)) end
video_jitterbuffer=(v)
click to toggle source
fluent video
# File lib/rairtame/client.rb, line 166 def video_jitterbuffer=(v) rpc_call(:setStreamerSettings, 'video_jb_flags', on_off_to_1_0(v)) end
Private Instance Methods
log_command(method, params)
click to toggle source
# File lib/rairtame/client.rb, line 209 def log_command(method, params) return unless @verbose puts "Sending command: [#{method} | #{params}]" end
log_response(r)
click to toggle source
# File lib/rairtame/client.rb, line 214 def log_response(r) # log anyway return unless @verbose is_error = Jsonrpctcp::Client.is_error?(r) if is_error then warn "Received error:" else puts "Received response:" end pp r end
on_off_to_1_0(value)
click to toggle source
# File lib/rairtame/client.rb, line 193 def on_off_to_1_0(value) case value when "off" then "0" when "on" then "1" else value end end
on_off_to_true_false(value)
click to toggle source
# File lib/rairtame/client.rb, line 201 def on_off_to_true_false(value) case value when "off" then "false" when "on" then "true" else value end end
resolve(host)
click to toggle source
# File lib/rairtame/client.rb, line 223 def resolve(host) begin IPAddr.new(host).to_s rescue IPAddr::InvalidAddressError Socket.getaddrinfo(host, nil)[0][3] end end