Class: Mooncell::Protocol::WebSocket::Server Private
- Inherits:
-
Object
- Object
- Mooncell::Protocol::WebSocket::Server
- Defined in:
- lib/mooncell/protocol/websocket/server.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
WebSocket Server implement
Instance Attribute Summary collapse
- #app ⇒ Object readonly private
Instance Method Summary collapse
-
#close(_event) ⇒ Object
private
On WebSocket close.
-
#initialize(app, env) ⇒ Server
constructor
private
Create WebSocket Server.
-
#message(event) ⇒ Object
private
On WebSocket receive data.
-
#open(_event) ⇒ Object
private
On WebSocket open.
-
#rack_response ⇒ Object
private
Rack Response.
-
#write(data) ⇒ Object
private
Writable API.
Constructor Details
#initialize(app, env) ⇒ Server
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create WebSocket Server
22 23 24 25 26 27 28 29 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 22 def initialize(app, env) @ws = Faye::WebSocket.new(env) @app = app @ws.on :open, method(:open) @ws.on :message, method(:message) @ws.on :close, method(:close) end |
Instance Attribute Details
#app ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 16 def app @app end |
Instance Method Details
#close(_event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
On WebSocket close
64 65 66 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 64 def close(_event) app.pool.delete(@conn) end |
#message(event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
On WebSocket receive data
51 52 53 54 55 56 57 58 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 51 def (event) # TODO: Support customize serializer params = JSON.parse(event.data) app.router.call(@conn, params) rescue JSON::ParserError # TODO: Handling error write(error: -1) end |
#open(_event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
On WebSocket open
43 44 45 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 43 def open(_event) @conn = Mooncell::Connection.new(self, app) end |
#rack_response ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Rack Response
35 36 37 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 35 def rack_response @ws.rack_response end |
#write(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writable API
72 73 74 |
# File 'lib/mooncell/protocol/websocket/server.rb', line 72 def write(data) @ws.send(data.to_json) end |