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.
Create a new Component
jid |
# File lib/xmpp4r/component.rb, line 26 def initialize(jid, server_address=nil, server_port=5347) super() @jid = (jid.kind_of?(JID) ? jid : JID.new(jid.to_s)) if server_address $stderr.puts "Passing server and port to Jabber::Component.new is " + "obsolete and will vanish in some later XMPP4R release. " + "Please use these arguments when calling " + "Jabber::Client#connect" @server_address = server_address @server_port = server_port end end
Send auth with given secret and wait for result
Throws ComponentAuthenticationFailure
secret |
|
# File lib/xmpp4r/component.rb, line 85 def auth(secret) hash = Digest::SHA1::hexdigest(@streamid.to_s + secret) authenticated = false send("<handshake>#{hash}</handshake>") { |r| if r.prefix == 'stream' and r.name == 'error' true elsif r.name == 'handshake' authenticated = true true else false end } unless authenticated raise ComponentAuthenticationFailure.new, "Component authentication failed" end end
Close the connection, sends </stream:stream> tag first
# File lib/xmpp4r/component.rb, line 57 def close send("</stream:stream>") super end
Connect to the server (chaining-friendly)
server |
|
port |
|
return |
self |
# File lib/xmpp4r/component.rb, line 45 def connect(server=nil, port=5347) if server super(server, port) else super(@server_address, @server_port) end self end
Generated with the Darkfish Rdoc Generator 2.