| 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.
| jid | [R] | The component‘s JID |
| server_address | [R] | The server‘s address |
| server_port | [R] | The server‘s port |
| jid: | [JID] |
# File lib/xmpp4r/component.rb, line 26
26: def initialize(jid, server_address=nil, server_port=5347)
27: super()
28: @jid = (jid.kind_of?(JID) ? jid : JID.new(jid.to_s))
29:
30: if server_address
31: $stderr.puts "Passing server and port to Jabber::Component.new is " +
32: "obsolete and will vanish in some later XMPP4R release. " +
33: "Please use these arguments when calling " +
34: "Jabber::Client#connect"
35: @server_address = server_address
36: @server_port = server_port
37: end
38: end
Send auth with given secret and wait for result
Throws ComponentAuthenticationFailure
| secret: | [String] the shared secret |
# File lib/xmpp4r/component.rb, line 85
85: def auth(secret)
86: hash = Digest::SHA1::hexdigest(@streamid.to_s + secret)
87: authenticated = false
88: send("<handshake>#{hash}</handshake>") { |r|
89: if r.prefix == 'stream' and r.name == 'error'
90: true
91: elsif r.name == 'handshake'
92: authenticated = true
93: true
94: else
95: false
96: end
97: }
98: unless authenticated
99: raise ComponentAuthenticationFailure.new, "Component authentication failed"
100: end
101: end
Close the connection, sends </stream:stream> tag first
# File lib/xmpp4r/component.rb, line 57
57: def close
58: send("</stream:stream>")
59: super
60: end
Connect to the server (chaining-friendly)
| server: | [String] Hostname |
| port: | [Integer] TCP port (5347) |
| return: | self |
# File lib/xmpp4r/component.rb, line 45
45: def connect(server=nil, port=5347)
46: if server
47: super(server, port)
48: else
49: super(@server_address, @server_port)
50: end
51: self
52: end