Class: XMPP4EM::Component

Inherits:
BaseClient show all
Defined in:
lib/xmpp4em/component.rb

Instance Attribute Summary

Attributes inherited from BaseClient

#authenticated, #connection, #user

Instance Method Summary collapse

Methods inherited from BaseClient

#add_iq_callback, #add_message_callback, #add_presence_callback, #close, #connected?, #on, #on_exception, #receive, #reconnect, #register_stanza, #send

Constructor Details

#initialize(user, pass, opts = {}) ⇒ Component

Returns a new instance of Component.



6
7
8
# File 'lib/xmpp4em/component.rb', line 6

def initialize user, pass, opts = {}
  super
end

Instance Method Details

#connect(host = jid.domain, port = 5222) ⇒ Object



14
15
16
17
18
19
# File 'lib/xmpp4em/component.rb', line 14

def connect host = jid.domain, port = 5222
  ::EM.connect host, port, ComponentConnection, jid.domain, port do |conn|
    @connection = conn
    conn.client = self
  end
end

#jidObject



10
11
12
# File 'lib/xmpp4em/component.rb', line 10

def jid
  @jid ||= @user.kind_of?(::Jabber::JID) ? @user : ::Jabber::JID.new(@user)
end

#receive_stanza(stanza) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/xmpp4em/component.rb', line 21

def receive_stanza(stanza)
  case stanza.name
    when 'stream'
      if !@authenticated && jid.domain == stanza.attributes['from']
        streamid = stanza.attributes['id']
        hash = Digest::SHA1::hexdigest(streamid.to_s + @pass)
        send("<handshake>#{hash}</handshake>")
      end
      return true
    when 'not-authorized'
      on(:error, 'not-authorized')
      return true
    when 'handshake'
      @authenticated = true
      on(:login, stanza)
      return true
  end

  false

end