Class: Openplay::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/openplay/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/openplay/client.rb', line 8

def initialize(options={})
  if options[:hostname]
    server = get_server_by_hostname(options[:hostname])
    raise "No server found with hostname #{options[:hostname]}" unless server
    @host = server.ip
    @port = server.port
  else
    @host = options[:host]
    @port = options[:port]
  end
  @resolution = options[:resolution] || screen_resolution
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/openplay/client.rb', line 6

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/openplay/client.rb', line 6

def port
  @port
end

Instance Method Details

#listObject

List available servers



34
35
36
# File 'lib/openplay/client.rb', line 34

def list
  DiscoversServers.find_servers
end

#throwObject

Throw video to a particular server



22
23
24
25
26
27
28
29
30
31
# File 'lib/openplay/client.rb', line 22

def throw
  options = []
  options << "-framerate ntsc"
  options << "-video_size #{@resolution}"
  options << "-f x11grab -i #{ENV['DISPLAY']}"
  options << "-f alsa -i pulse"
  options << "-vcodec libx264 -tune zerolatency -crf 26 -preset ultrafast"
  options << "-f mpegts udp://#{host}:#{port}?pkt_size=#{packet_size}"
  `ffmpeg #{options.join(' ')}`
end