class Jabber::Component

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.

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) click to toggle source

Create a new Component

jid
JID
Calls superclass method
# 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

Public Instance Methods

auth(secret) click to toggle source

Send auth with given secret and wait for result

Throws ComponentAuthenticationFailure

secret
String

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() click to toggle source

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

Calls superclass method
# File lib/xmpp4r/component.rb, line 57
def close
  send("</stream:stream>")
  super
end
connect(server=nil, port=5347) click to toggle source

Connect to the server (chaining-friendly)

server
String

Hostname

port
Integer

TCP port (5347)

return

self

Calls superclass method
# 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() click to toggle source

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

Calls superclass method
# 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

Private Instance Methods

generate_stream_start(to=nil, from=nil, id=nil, xml_lang="en", xmlns="jabber:component:accept", version="1.0") click to toggle source
Calls superclass method
# 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