Class: Iodine::Http::WebsocketHandler
- Inherits:
-
Object
- Object
- Iodine::Http::WebsocketHandler
- Defined in:
- lib/iodine/http/websocket_handler.rb
Overview
This class is a good demonstration for creating a Websocket handler with the Iodine API.
Iodine is Object Oriented and for this reason the Websocket handler is expected to retain the information it needs - either through initialization, or through the ‘on_open(protocol)` callback.
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
The original Http request.
-
#response ⇒ Object
readonly
The Http response, also allowing for websocket data.
Class Method Summary collapse
-
.call(request, response) ⇒ Object
This method allows the class itself to act as the Websocket handler, usable with: Iodine::Http.on_websocket Iodine::Http::WebsocketEchoDemo.
Instance Method Summary collapse
-
#initialize(request, response) ⇒ WebsocketHandler
constructor
this is called while still communicating over Http (during the upgrade process).
-
#on_broadcast(data) ⇒ Object
Accept unicasts or broadcasts using this callback.
-
#on_close ⇒ Object
cleanup, if needed, using this callback.
-
#on_message(data) ⇒ Object
Accept data using this callback - this is a required callback.
-
#on_open ⇒ Object
initialize the protocol data once the connection had opened.
Constructor Details
#initialize(request, response) ⇒ WebsocketHandler
this is called while still communicating over Http (during the upgrade process).
15 16 17 18 |
# File 'lib/iodine/http/websocket_handler.rb', line 15 def initialize request, response @request = request @response = response end |
Instance Attribute Details
#request ⇒ Object (readonly)
The original Http request
11 12 13 |
# File 'lib/iodine/http/websocket_handler.rb', line 11 def request @request end |
#response ⇒ Object (readonly)
The Http response, also allowing for websocket data
13 14 15 |
# File 'lib/iodine/http/websocket_handler.rb', line 13 def response @response end |
Class Method Details
.call(request, response) ⇒ Object
This method allows the class itself to act as the Websocket handler, usable with:
Iodine::Http.on_websocket Iodine::Http::WebsocketEchoDemo
34 35 36 |
# File 'lib/iodine/http/websocket_handler.rb', line 34 def self.call request, response self.new request, response end |
Instance Method Details
#on_broadcast(data) ⇒ Object
Accept unicasts or broadcasts using this callback.
26 27 |
# File 'lib/iodine/http/websocket_handler.rb', line 26 def on_broadcast data end |
#on_close ⇒ Object
cleanup, if needed, using this callback.
29 30 |
# File 'lib/iodine/http/websocket_handler.rb', line 29 def on_close end |
#on_message(data) ⇒ Object
Accept data using this callback - this is a required callback.
23 24 |
# File 'lib/iodine/http/websocket_handler.rb', line 23 def data end |
#on_open ⇒ Object
initialize the protocol data once the connection had opened.
20 21 |
# File 'lib/iodine/http/websocket_handler.rb', line 20 def on_open end |