| 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, threaded = true)
27: super(threaded)
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 AuthenticationFailure
| secret: | [String] the shared secret |
# File lib/xmpp4r/component.rb, line 85
85: def auth(secret)
86: hash = Digest::SHA1::new(@streamid.to_s + secret).to_s
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 AuthenticationFailure.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
Start the stream-parser and send the component-specific stream opening element
# File lib/xmpp4r/component.rb, line 69
69: def start
70: super
71: send(generate_stream_start(@jid)) { |e|
72: if e.name == 'stream'
73: true
74: else
75: false
76: end
77: }
78: end