Class: PageWebSocket

Inherits:
WebSocketHelper show all
Defined in:
lib/sinatra/liveviews/page-websocket.rb

Instance Attribute Summary

Attributes inherited from WebSocketHelper

#latency

Instance Method Summary collapse

Methods inherited from WebSocketHelper

#on_message, #send, #send_all, #send_others, #simulate_latency

Constructor Details

#initialize(ws, options = {}) ⇒ PageWebSocket

Returns a new instance of PageWebSocket.



5
6
7
8
9
10
11
# File 'lib/sinatra/liveviews/page-websocket.rb', line 5

def initialize(ws, options = {})
	super(ws)

	# todo: validate the url and the app instances
	@app = options[:app]
	@url = options[:url]
end

Instance Method Details

#documentObject



33
34
35
36
37
38
39
40
# File 'lib/sinatra/liveviews/page-websocket.rb', line 33

def document
	if @document.nil?
		@document = ClientDocument.new(self)
		@document.location = @url
	end

	return @document
end

#on_closeObject



29
30
31
# File 'lib/sinatra/liveviews/page-websocket.rb', line 29

def on_close
	super
end

#on_openObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sinatra/liveviews/page-websocket.rb', line 13

def on_open
	super

	uri = URI.parse(@url)
	path = uri.path
	method_name = @app.class._method_name('LIVE', path)

	if @app.respond_to? method_name
		@app.send(method_name, document)
	else
		# send an error back to the client
		self.send 'message', { :content => "no live handler for #{path}" }
	end

end