Class: Sarb::Connection
- Inherits:
-
Object
- Object
- Sarb::Connection
- Defined in:
- lib/sarb/connection.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app, ws) ⇒ Connection
constructor
A new instance of Connection.
- #message(message) ⇒ Object
- #onclose(event) ⇒ Object
- #onmessage(message) ⇒ Object
- #onopen(handshake) ⇒ Object
Constructor Details
#initialize(app, ws) ⇒ Connection
Returns a new instance of Connection.
3 4 5 6 |
# File 'lib/sarb/connection.rb', line 3 def initialize(app, ws) @app = app @ws = ws end |
Class Method Details
.setup(app, ws) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/sarb/connection.rb', line 24 def self.setup(app, ws) connection = Connection.new(app, ws) ws.onopen &connection.method(:onopen) ws. &connection.method(:onmessage) ws.onclose &connection.method(:onclose) connection end |
Instance Method Details
#message(message) ⇒ Object
20 21 22 |
# File 'lib/sarb/connection.rb', line 20 def () @ws.send(.to_json) end |
#onclose(event) ⇒ Object
16 17 18 |
# File 'lib/sarb/connection.rb', line 16 def onclose(event) @app.trigger :connection_close, :connection => self end |
#onmessage(message) ⇒ Object
12 13 14 |
# File 'lib/sarb/connection.rb', line 12 def () @app.invoke self, end |
#onopen(handshake) ⇒ Object
8 9 10 |
# File 'lib/sarb/connection.rb', line 8 def onopen(handshake) @app.trigger :connection_open, :connection => self end |