Class: EventMachine::CometIO::Client
- Inherits:
-
Object
- Object
- EventMachine::CometIO::Client
- Includes:
- EventEmitter
- Defined in:
- lib/em-cometio-client.rb,
lib/em-cometio-client/client.rb,
lib/em-cometio-client/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
- #push(type, data) ⇒ Object
Constructor Details
#initialize(url) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/em-cometio-client/client.rb', line 8 def initialize(url) raise ArgumentError, "invalid URL (#{url})" unless url.kind_of? String and url =~ /^https?:\/\/.+/ @url = url @session = nil @running = false @timeout = 120 @post_queue = [] EM::add_periodic_timer 1 do flush end end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
5 6 7 |
# File 'lib/em-cometio-client/client.rb', line 5 def session @session end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/em-cometio-client/client.rb', line 6 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/em-cometio-client/client.rb', line 5 def url @url end |
Instance Method Details
#close ⇒ Object
55 56 57 58 |
# File 'lib/em-cometio-client/client.rb', line 55 def close @running = false self.remove_listener :__session_id end |
#connect ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/em-cometio-client/client.rb', line 44 def connect return self if @running self.on :__session_id do |session| @session = session self.emit :connect, @session end @running = true get return self end |
#push(type, data) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/em-cometio-client/client.rb', line 36 def push(type, data) if !@running or !@session emit :error, "CometIO not connected" return end @post_queue.push :type => type, :data => data end |