Class: Slanger::Connection
- Inherits:
-
Object
- Object
- Slanger::Connection
- Defined in:
- lib/slanger/connection.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#socket_id ⇒ Object
Returns the value of attribute socket_id.
Instance Method Summary collapse
- #error(e) ⇒ Object
- #establish ⇒ Object
-
#initialize(socket, socket_id = nil) ⇒ Connection
constructor
A new instance of Connection.
- #send_message(m) ⇒ Object
- #send_payload(*args) ⇒ Object
Constructor Details
#initialize(socket, socket_id = nil) ⇒ Connection
Returns a new instance of Connection.
5 6 7 |
# File 'lib/slanger/connection.rb', line 5 def initialize socket, socket_id=nil @socket, @socket_id = socket, socket_id end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
3 4 5 |
# File 'lib/slanger/connection.rb', line 3 def socket @socket end |
#socket_id ⇒ Object
Returns the value of attribute socket_id.
3 4 5 |
# File 'lib/slanger/connection.rb', line 3 def socket_id @socket_id end |
Instance Method Details
#error(e) ⇒ Object
19 20 21 |
# File 'lib/slanger/connection.rb', line 19 def error e send_payload nil, 'pusher:error', e end |
#establish ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/slanger/connection.rb', line 23 def establish @socket_id = SecureRandom.uuid send_payload nil, 'pusher:connection_established', { socket_id: @socket_id, activity_timeout: Slanger::Config.activity_timeout } end |
#send_message(m) ⇒ Object
9 10 11 12 13 |
# File 'lib/slanger/connection.rb', line 9 def m msg = JSON.parse m s = msg.delete 'socket_id' socket.send msg.to_json unless s == socket_id end |
#send_payload(*args) ⇒ Object
15 16 17 |
# File 'lib/slanger/connection.rb', line 15 def send_payload *args socket.send format(*args) end |