Class: VncShare
- Inherits:
-
Object
- Object
- VncShare
- Defined in:
- lib/network-projector/vnc/share.rb
Constant Summary collapse
- CMD =
"x11vnc -once -ncache"
Instance Attribute Summary collapse
-
#passwd ⇒ Object
readonly
Returns the value of attribute passwd.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ VncShare
constructor
A new instance of VncShare.
- #join ⇒ Object
- #run ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ VncShare
Returns a new instance of VncShare.
9 10 11 12 13 |
# File 'lib/network-projector/vnc/share.rb', line 9 def initialize = {} @passwd = [:passwd] @display = [:display] @clip = [:clip] end |
Instance Attribute Details
#passwd ⇒ Object (readonly)
Returns the value of attribute passwd.
5 6 7 |
# File 'lib/network-projector/vnc/share.rb', line 5 def passwd @passwd end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/network-projector/vnc/share.rb', line 5 def port @port end |
Instance Method Details
#join ⇒ Object
55 56 57 |
# File 'lib/network-projector/vnc/share.rb', line 55 def join @thread.join if @thread end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/network-projector/vnc/share.rb', line 15 def run cmd = CMD cmd += " -display #{@display}" if @display cmd += " -noshm" if @display and @display != ":0" cmd += " -passwd #{@passwd}" if @display cmd += " -clip #{@clip}" if @clip cmd += " -loop" @vnc_pin, @vnc_pout, @thread = Open3.popen2e(cmd) raise "Can't share desktop" unless @thread @port = nil @log_lines = "" @vnc_pout.each_line do |line| @log_lines += line m = /PORT=(\d+)/.match(line) if m then @port = m[1] break end end if @port then puts "Vnc running on port #{@port}" else puts "Something went wrong :" puts @log_lines stop end end |
#started? ⇒ Boolean
46 47 48 |
# File 'lib/network-projector/vnc/share.rb', line 46 def started? @thread != nil end |
#stop ⇒ Object
49 50 51 52 53 |
# File 'lib/network-projector/vnc/share.rb', line 49 def stop return unless @thread @thread.kill join end |