Class: AgentXmpp::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EventMachine::XmlPushParser
Defined in:
lib/agent_xmpp/client/connection.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Connection

.….….….….….….….….….….….….….….….….….….….….….….….….….….



16
17
18
19
# File 'lib/agent_xmpp/client/connection.rb', line 16

def initialize(client)
  @client = client
  @pipe = MessagePipe.new(self)
end

Instance Attribute Details

#clientObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def client
  @client
end

#delegatesObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def delegates
  @delegates
end

#keepaliveObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def keepalive
  @keepalive
end

#pipeObject (readonly)




12
13
14
# File 'lib/agent_xmpp/client/connection.rb', line 12

def pipe
  @pipe
end

Instance Method Details

#characters(text) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



73
74
75
# File 'lib/agent_xmpp/client/connection.rb', line 73

def characters(text)
  @current.text = @current.text.to_s + text if @current
end

#connection_completedObject


EventMachine::Connection callbacks .….….….….….….….….….….….….….….….….….….….….….….….….….….



24
25
26
27
28
29
# File 'lib/agent_xmpp/client/connection.rb', line 24

def connection_completed
  @keepalive = EventMachine::PeriodicTimer.new(60) do 
    send_data("\n")
  end
  pipe.connection_completed
end

#end_element(name) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



63
64
65
66
67
68
69
70
# File 'lib/agent_xmpp/client/connection.rb', line 63

def end_element(name)
  if @current.parent
    @current = @current.parent
  else
    process
    @current = nil
  end
end

#error(*args) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



78
79
80
# File 'lib/agent_xmpp/client/connection.rb', line 78

def error(*args)
  AgentXmpp.logger.error *args
end

#processObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/agent_xmpp/client/connection.rb', line 83

def process
  @current.add_namespace(@streamns) if @current.namespace('').to_s.eql?('')
  begin
    stanza = Xmpp::Stanza::import(@current)
  rescue Xmpp::NoNameXmlnsRegistered
    stanza = @current
  end
  if @current.xpath.eql?('stream:stream')
    @streamns = @current.namespace('') if @current.namespace('')
  end
  receive(stanza) if respond_to?(:receive)
end

#receive(stanza) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



97
98
99
# File 'lib/agent_xmpp/client/connection.rb', line 97

def receive(stanza)
  pipe.receive(stanza)
end

#receive_data(data) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



32
33
34
# File 'lib/agent_xmpp/client/connection.rb', line 32

def receive_data(data)
  super(data)
end

#start_documentObject


EventMachine::XmlPushParser callbacks .….….….….….….….….….….….….….….….….….….….….….….….….….….



48
49
# File 'lib/agent_xmpp/client/connection.rb', line 48

def start_document
end

#start_element(name, attrs) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



52
53
54
55
56
57
58
59
60
# File 'lib/agent_xmpp/client/connection.rb', line 52

def start_element(name, attrs)
  e = REXML::Element.new(name)
  e.add_attributes(attrs)      
  @current = @current.nil? ? e : @current.add_element(e)  
  if @current.xpath == 'stream:stream'
    process
    @current = nil
  end
end

#unbindObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



37
38
39
40
41
42
43
# File 'lib/agent_xmpp/client/connection.rb', line 37

def unbind
  if @keepalive
    @keepalive.cancel
    @keepalive = nil
  end
  pipe.unbind
end