Class: XMPP4EM::BaseConnection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- XMPP4EM::BaseConnection
show all
- Defined in:
- lib/xmpp4em/base_connection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(host, port = 5222) ⇒ BaseConnection
Returns a new instance of BaseConnection.
63
64
65
66
67
68
69
70
71
|
# File 'lib/xmpp4em/base_connection.rb', line 63
def initialize host, port=5222
@host, @port = host, port
@client = nil
@pushParser=::XMPP4EM::XmppPushParser.new
@pushParser.process do |c|
process(c)
end
@parser=::Nokogiri::XML::SAX::PushParser.new(@pushParser)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
73
74
75
|
# File 'lib/xmpp4em/base_connection.rb', line 73
def client
@client
end
|
#host ⇒ Object
Returns the value of attribute host.
73
74
75
|
# File 'lib/xmpp4em/base_connection.rb', line 73
def host
@host
end
|
#logger ⇒ Object
Returns the value of attribute logger.
73
74
75
|
# File 'lib/xmpp4em/base_connection.rb', line 73
def logger
@logger
end
|
#port ⇒ Object
Returns the value of attribute port.
73
74
75
|
# File 'lib/xmpp4em/base_connection.rb', line 73
def port
@port
end
|
#stream_features ⇒ Object
Returns the value of attribute stream_features.
83
84
85
|
# File 'lib/xmpp4em/base_connection.rb', line 83
def stream_features
@stream_features
end
|
Instance Method Details
#connection_completed ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/xmpp4em/base_connection.rb', line 75
def connection_completed
@logger.debug { 'connected' } if @logger
@stream_features, @stream_mechanisms = {}, []
@keepalive = ::EM::Timer.new(60) { send_data("\n") }
@client.on(:connected)
init
end
|
#error(*args) ⇒ Object
85
86
87
|
# File 'lib/xmpp4em/base_connection.rb', line 85
def error *args
$stderr.puts ['error', *args]
end
|
#init ⇒ Object
114
115
116
117
118
|
# File 'lib/xmpp4em/base_connection.rb', line 114
def init
send "<?xml version='1.0' ?>" unless @pushParser.started
@pushParser.started = false
send "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='#{namespace;}' xml:lang='en' version='1.0' to='#{@host}'>"
end
|
#receive_data(data) ⇒ Object
89
90
91
92
93
|
# File 'lib/xmpp4em/base_connection.rb', line 89
def receive_data data
@logger.debug { "<< #{data}" } if @logger
@parser.write(data)
end
|
#reconnect(host = @host, port = @port) ⇒ Object
110
111
112
|
# File 'lib/xmpp4em/base_connection.rb', line 110
def reconnect host = @host, port = @port
super
end
|
#send(data, &blk) ⇒ Object
95
96
97
98
99
|
# File 'lib/xmpp4em/base_connection.rb', line 95
def send data, &blk
@logger.debug { ">> #{data}" } if @logger
send_data data.to_s
end
|
#unbind ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/xmpp4em/base_connection.rb', line 101
def unbind
if @keepalive
@keepalive.cancel
@keepalive = nil
end
@client.on(:disconnect)
@logger.debug { 'disconnected' } if @logger
end
|