Class: Kibosh::XMPP::Session::Stream
Instance Attribute Summary collapse
#connection, #driver, #from, #route, #secure, #session, #to
Instance Method Summary
collapse
#abort, #body, #body=, #close, #id, #lock, #respond, #stop, #terminate, #terminate!
Constructor Details
#initialize(object, request, response) ⇒ Stream
Returns a new instance of Stream.
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 18
def initialize object, request, response
case object
when Kibosh::XMPP::Session::Stream
other = object
super
response.stream = self
(@connection = other.connection).restart self
when Kibosh::XMPP::Session
super { |response| yield response }
else
raise "hell"
end
end
|
Instance Attribute Details
#xmpp_id ⇒ Object
Returns the value of attribute xmpp_id.
12
13
14
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 12
def xmpp_id
@xmpp_id
end
|
Instance Method Details
#connect(request, response) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 32
def connect request, response
result = nil
case string = request.driver( @session, @to, @route )
when :local
raise "implement"
when String
match = %r{^\s*([^:]+)(:(.*))?\s*$}.match string
raise InternalServerError.new @session,
"#{@to} unknown/unreachable via #{string}" if !match
host = match[1]
port = match[3] || 5222
raise "hell" if @body
@body = response.defer
EM::connect host, port, Kibosh::XMPP::Client::Connection, self,
lambda { |connection|
@connection = connection
},
lambda { |connection|
self.body.extend(RemoteConnectionFailed)
respond
}
when nil
raise "implement"
else
raise UndefinedCondition.new @session, "No Kibosh route for #{@to}"
end
response
end
|
#handle(request, response) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 70
def handle request, response
if request.body.inner_html && request.body.inner_html != ""
puts "> #{request.body.inner_html}"
@connection.send_data request.body.inner_html
end
if request.body["type"] == "terminate"
@connection.terminate
terminate request, response
else
response.defer
response
end
end
|
#ready! ⇒ Object
84
85
86
87
88
89
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 84
def ready!
if @body["type"] == "terminate" and @body["condition"] == "remote-stream-error"
terminate!
end
super
end
|
#restart(request, response) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 63
def restart request, response
self.class.new self, request, response
self.abort
response.defer
response
end
|
#version ⇒ Object
14
15
16
|
# File 'lib/kibosh/xmpp/session/stream.rb', line 14
def version
@session.version
end
|