Class: Babylon::ComponentConnection
- Inherits:
-
XmppConnection
- Object
- EventMachine::Connection
- XmppConnection
- Babylon::ComponentConnection
- Defined in:
- lib/babylon/component_connection.rb
Overview
ComponentConnection is in charge of the XMPP connection itself. Upon stanza reception, and depending on the status (connected… etc), this component will handle or forward the stanzas.
Instance Attribute Summary
Attributes inherited from XmppConnection
Instance Method Summary collapse
-
#connection_completed ⇒ Object
Connection_completed is called when the connection (socket) has been established and is in charge of “building” the XML stream to establish the XMPP connection itself.
-
#initialize(params) ⇒ ComponentConnection
constructor
Creates a new ComponentConnection and waits for data in the stream.
-
#receive_stanza(stanza) ⇒ Object
XMPP Component handshake as defined in XEP-0114: xmpp.org/extensions/xep-0114.html.
-
#stream_namespace ⇒ Object
Namespace of the component.
Methods inherited from XmppConnection
connect, max_stanza_size, max_stanza_size=, #post_init, #send_xml, #unbind
Constructor Details
#initialize(params) ⇒ ComponentConnection
Creates a new ComponentConnection and waits for data in the stream
9 10 11 12 |
# File 'lib/babylon/component_connection.rb', line 9 def initialize(params) super(params) @state = :wait_for_stream end |
Instance Method Details
#connection_completed ⇒ Object
Connection_completed is called when the connection (socket) has been established and is in charge of “building” the XML stream to establish the XMPP connection itself. We use a “tweak” here to send only the starting tag of stream:stream
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/babylon/component_connection.rb', line 18 def connection_completed super doc = Nokogiri::XML::Document.new stream = Nokogiri::XML::Node.new("stream:stream", doc) stream["xmlns"] = stream_namespace stream["xmlns:stream"] = "http://etherx.jabber.org/streams" stream["to"] = jid doc.add_child(stream) paste_content_here= Nokogiri::XML::Node.new("paste_content_here", doc) stream.add_child(paste_content_here) start, stop = doc.to_xml.split('<paste_content_here/>') send_xml(start) end |
#receive_stanza(stanza) ⇒ Object
XMPP Component handshake as defined in XEP-0114: xmpp.org/extensions/xep-0114.html
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 62 63 64 65 66 67 |
# File 'lib/babylon/component_connection.rb', line 35 def receive_stanza(stanza) case @state when :connected # Most frequent case super(stanza) # Can be dispatched when :wait_for_stream if stanza.name == "stream:stream" && stanza.attributes['id'] # This means the XMPP session started! # We must send the handshake now. send_xml(handshake(stanza)) @state = :wait_for_handshake else raise end when :wait_for_handshake if stanza.name == "handshake" begin @handler.on_connected(self) if @handler and @handler.respond_to?("on_connected") rescue Babylon.logger.error { "on_connected failed : #{$!}\n#{$!.backtrace.join("\n")}" } end @state = :connected elsif stanza.name == "stream:error" raise AuthenticationError else raise end end end |
#stream_namespace ⇒ Object
Namespace of the component
71 72 73 |
# File 'lib/babylon/component_connection.rb', line 71 def stream_namespace 'jabber:component:accept' end |