Class Babylon::ComponentConnection
In: lib/babylon/component_connection.rb
Parent: XmppConnection

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.

Methods

Public Class methods

Creates a new ComponentConnection and waits for data in the stream

[Source]

    # File lib/babylon/component_connection.rb, line 9
 9:     def initialize(params)
10:       super(params)
11:       @state = :wait_for_stream
12:     end

Public Instance methods

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

[Source]

    # File lib/babylon/component_connection.rb, line 18
18:     def connection_completed
19:       super
20:       doc = Nokogiri::XML::Document.new 
21:       stream = Nokogiri::XML::Node.new("stream:stream", doc)
22:       stream["xmlns"] = stream_namespace
23:       stream["xmlns:stream"] = "http://etherx.jabber.org/streams"
24:       stream["to"] = jid
25:       doc.add_child(stream)
26:       paste_content_here= Nokogiri::XML::Node.new("paste_content_here", doc)
27:       stream.add_child(paste_content_here)
28:       start, stop = doc.to_xml.split('<paste_content_here/>')
29:       send_xml(start)
30:     end

XMPP Component handshake as defined in XEP-0114: xmpp.org/extensions/xep-0114.html

[Source]

    # File lib/babylon/component_connection.rb, line 35
35:     def receive_stanza(stanza)
36:       case @state
37:       when :connected # Most frequent case
38:           super(stanza) # Can be dispatched
39:           
40:       when :wait_for_stream
41:         if stanza.name == "stream:stream" && stanza.attributes['id']
42:           # This means the XMPP session started!
43:           # We must send the handshake now.
44:           send_xml(handshake(stanza))
45:           @state = :wait_for_handshake
46:         else
47:           raise
48:         end
49: 
50:       when :wait_for_handshake
51:         if stanza.name == "handshake"
52:           begin
53:             @handler.on_connected(self) if @handler and @handler.respond_to?("on_connected")
54:           rescue
55:             Babylon.logger.error {
56:               "on_connected failed : #{$!}\n#{$!.backtrace.join("\n")}"
57:             }
58:           end
59:           @state = :connected
60:         elsif stanza.name == "stream:error"
61:           raise AuthenticationError
62:         else
63:           raise
64:         end
65: 
66:       end
67:     end

Namespace of the component

[Source]

    # File lib/babylon/component_connection.rb, line 71
71:     def stream_namespace
72:       'jabber:component:accept'
73:     end

[Validate]