Class: Blather::Stream::Component

Inherits:
Blather::Stream
  • Object
show all
Defined in:
lib/blather/stream/component.rb

Constant Summary collapse

NAMESPACE =
'jabber:component:accept'

Constants inherited from Blather::Stream

STREAM_NS

Instance Attribute Summary

Attributes inherited from Blather::Stream

#jid, #password

Instance Method Summary collapse

Methods inherited from Blather::Stream

connect, #connection_completed, #initialize, #post_init, #receive_data, start, #unbind

Constructor Details

This class inherits a constructor from Blather::Stream

Instance Method Details

#receive(node) ⇒ Object

:nodoc:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blather/stream/component.rb', line 7

def receive(node) # :nodoc:
  if node.element_name == 'handshake'
    ready!
  else
    super
  end

  if node.document.find_first('/stream:stream[not(stream:error)]', :xmlns => NAMESPACE, :stream => STREAM_NS)
    send("<handshake>#{Digest::SHA1.hexdigest(@node['id']+@password)}</handshake>")
  end
end

#send(stanza) ⇒ Object



19
20
21
22
# File 'lib/blather/stream/component.rb', line 19

def send(stanza)
  stanza.from ||= self.jid if stanza.respond_to?(:from) && stanza.respond_to?(:from=)
  super stanza
end

#startObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/blather/stream/component.rb', line 24

def start
  @parser = Parser.new self
  start_stream = <<-STREAM
    <stream:stream
      to='#{@jid}'
      xmlns='#{NAMESPACE}'
      xmlns:stream='#{STREAM_NS}'
    >
  STREAM
  send start_stream.gsub(/\s+/, ' ')
end