Class: VncShare

Inherits:
Object
  • Object
show all
Defined in:
lib/network-projector/vnc/share.rb

Constant Summary collapse

CMD =
"x11vnc -once -ncache"

Instance Attribute Summary collapse

Instance Method Summary collapse

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 options = {}
	@passwd = options[:passwd]
	@display = options[:display]
	@clip = options[:clip]
end

Instance Attribute Details

#passwdObject (readonly)

Returns the value of attribute passwd.



5
6
7
# File 'lib/network-projector/vnc/share.rb', line 5

def passwd
  @passwd
end

#portObject (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

#joinObject



55
56
57
# File 'lib/network-projector/vnc/share.rb', line 55

def join
	@thread.join if @thread
end

#runObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/network-projector/vnc/share.rb', line 46

def started?
	@thread != nil
end

#stopObject



49
50
51
52
53
# File 'lib/network-projector/vnc/share.rb', line 49

def stop
	return unless @thread
	@thread.kill
	join
end