Class Jabber::Component
In: lib/xmpp4r/component.rb
Parent: Connection
X XDelay XMuc XRoster XMucUser REXML::Element XRosterItem IqQuery XMLStanza IqVcard DiscoIdentity XMucUserItem DiscoItem Error RosterItem DiscoFeature IqQueryRoster IqQueryVersion IqQueryDiscoItems IqQueryDiscoInfo Message Presence Iq Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure RosterItem Stream StreamParser Roster Vcard Version lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/iq/query/roster.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/iq/query/version.rb lib/xmpp4r/connection.rb lib/xmpp4r/x/mucuseritem.rb lib/xmpp4r/x/roster.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/iq/query.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/x/delay.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x/muc.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/iq/vcard.rb lib/xmpp4r/iq/query/discoinfo.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/message.rb lib/xmpp4r/iq/query/discoitems.rb lib/xmpp4r/presence.rb lib/xmpp4r/helpers/roster.rb lib/xmpp4r/helpers/vcard.rb lib/xmpp4r/helpers/version.rb Helpers Jabber Module: Jabber

The component class provides everything needed to build a XMPP Component.

Components are more flexible as they are only restricted in the use of a fixed domain. node and resource of JIDs are freely choosable for all stanzas.

Methods

auth   close   connect   new  

Attributes

jid  [R]  The component’s JID
server_address  [R]  The server’s address
server_port  [R]  The server’s port

Public Class methods

Create a new Component

jid:[JID]
server_address:[String] Hostname
server_port:[Integer] TCP port (5347)

[Source]

    # File lib/xmpp4r/component.rb, line 28
28:     def initialize(jid, server_address, server_port=5347, threaded = true)
29:       super(threaded)
30:       @jid = jid
31:       @server_address = server_address
32:       @server_port = server_port
33:     end

Public Instance methods

Send auth with given secret and wait for result

Throws AuthenticationFailure

secret:[String] the shared secret

[Source]

    # File lib/xmpp4r/component.rb, line 62
62:     def auth(secret)
63:       hash = Digest::SHA1::new(@streamid.to_s + secret).to_s
64:       authenticated = false
65:       send("<handshake>#{hash}</handshake>") { |r|
66:         if r.prefix == 'stream' and r.name == 'error'
67:           true
68:         elsif r.name == 'handshake' and r.namespace == 'jabber:component:accept'
69:           authenticated = true
70:           true
71:         else
72:           false
73:         end
74:       }
75:       unless authenticated
76:         raise AuthenticationFailure.new, "Component authentication failed"
77:       end
78:     end

Close the connection, sends </stream:stream> tag first

[Source]

    # File lib/xmpp4r/component.rb, line 53
53:     def close
54:       send("</stream:stream>")
55:       super
56:     end

Connect to the server (chaining-friendly)

return:self

[Source]

    # File lib/xmpp4r/component.rb, line 38
38:     def connect
39:       super(@server_address, @server_port)
40:       send("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:component:accept' to='#{@jid}'>") { |e|
41:         if e.name == 'stream'
42:           true
43:         else
44:           false
45:         end
46:       }
47:       self
48:     end

[Validate]