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.
The component's JID
The server's address
The server's port
Create a new Component
# 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
the shared 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)
Hostname
TCP port (5347)
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
Start the stream-parser and send the component-specific stream opening element
# File lib/xmpp4r/component.rb, line 69 def start super send(generate_stream_start(@jid)) { |e| if e.name == 'stream' true else false end } end
# File lib/xmpp4r/component.rb, line 62 def generate_stream_start(to=nil, from=nil, id=nil, xml_lang="en", xmlns="jabber:component:accept", version="1.0") super end