Class: SimplePusher::Connection
- Inherits:
-
Object
- Object
- SimplePusher::Connection
- Defined in:
- lib/simple_pusher/connection.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#websocket ⇒ Object
Returns the value of attribute websocket.
Class Method Summary collapse
- .add_client(socket) ⇒ Object
- .callbacks ⇒ Object
- .clients ⇒ Object
- .count ⇒ Object
- .on(event, &callback) ⇒ Object
- .publish(channel, message) ⇒ Object
- .remove_client(socket) ⇒ Object
- .trigger(event) ⇒ Object
Instance Method Summary collapse
- #emit(message) ⇒ Object
-
#initialize(websocket) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(websocket) ⇒ Connection
Returns a new instance of Connection.
43 44 45 |
# File 'lib/simple_pusher/connection.rb', line 43 def initialize(websocket) @websocket = websocket end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/simple_pusher/connection.rb', line 4 def name @name end |
#websocket ⇒ Object
Returns the value of attribute websocket.
3 4 5 |
# File 'lib/simple_pusher/connection.rb', line 3 def websocket @websocket end |
Class Method Details
.add_client(socket) ⇒ Object
24 25 26 27 |
# File 'lib/simple_pusher/connection.rb', line 24 def self.add_client(socket) client = new(socket) clients[socket] = client end |
.callbacks ⇒ Object
10 11 12 |
# File 'lib/simple_pusher/connection.rb', line 10 def self.callbacks @@callbacks ||= {} end |
.clients ⇒ Object
6 7 8 |
# File 'lib/simple_pusher/connection.rb', line 6 def self.clients @@clients ||= {} end |
.count ⇒ Object
39 40 41 |
# File 'lib/simple_pusher/connection.rb', line 39 def self.count clients.size end |
.on(event, &callback) ⇒ Object
14 15 16 17 |
# File 'lib/simple_pusher/connection.rb', line 14 def self.on(event, &callback) callbacks[event] ||= [] callbacks[event] << callback end |
.publish(channel, message) ⇒ Object
33 34 35 36 37 |
# File 'lib/simple_pusher/connection.rb', line 33 def self.publish(channel, ) clients.each do |websocket, _client| websocket.send "#{channel}:#{}" end end |
.remove_client(socket) ⇒ Object
29 30 31 |
# File 'lib/simple_pusher/connection.rb', line 29 def self.remove_client(socket) clients.delete(socket) end |
.trigger(event) ⇒ Object
19 20 21 22 |
# File 'lib/simple_pusher/connection.rb', line 19 def self.trigger(event) callbacks[event] ||= [] callbacks[event].each { |callback| callback.call } end |
Instance Method Details
#emit(message) ⇒ Object
47 48 49 |
# File 'lib/simple_pusher/connection.rb', line 47 def emit() @websocket.send() end |