Class: Jabber::Component

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 start

### Attributes

jid | [R] | The component‘s JID
server_address | [R] | The server‘s address
server_port | [R] | The server‘s port

### Public Class methods

new(jid, server_address=nil, server_port=5347)

Create a new Component

jid: | [JID]

[Source]

        # 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

### Public Instance methods

auth(secret)

Send auth with given secret and wait for result

Throws ComponentAuthenticationFailure

secret: | [String] the shared secret

[Source]

         # 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()

Close the connection, sends `</stream:stream>` tag first

[Source]

        # File lib/xmpp4r/component.rb, line 57
    57:     def close
    58:       send("</stream:stream>")
    59:       super
    60:     end

connect(server=nil, port=5347)

Connect to the server (chaining-friendly)

server: | [String] Hostname
port: | [Integer] TCP port (5347)
return: | self

[Source]

        # 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()

Start the stream-parser and send the component-specific stream opening element

[Source]

        # 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

[Validate]