Class Jabber::Component
In: lib/xmpp4r/component.rb
Parent: Connection

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]