Module: DDP::Server::Protocol
- Included in:
- WebSocket
- Defined in:
- lib/ddp/server/protocol.rb,
lib/ddp/server/protocol/rpc.rb,
lib/ddp/server/protocol/data.rb,
lib/ddp/server/protocol/heartbeat.rb
Overview
Implementation of the DDP protocol Can be included into any class that has an on_open, a read_message and a write_message method
Defined Under Namespace
Constant Summary collapse
- DDP_VERSION =
'1'
Constants included from RPC
Instance Attribute Summary collapse
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Instance Method Summary collapse
- #handle_connect ⇒ Object
- #handle_established ⇒ Object
- #handle_session(message) ⇒ Object
- #new_session_id ⇒ Object
Methods included from RPC
#handle_method, #handle_rpc, #send_error_result, #send_result, #send_updated
Methods included from Data
#handle_data, #handle_sub, #handle_unsub, #send_added, #send_added_before, #send_changed, #send_moved_before, #send_nosub, #send_ready, #send_removed, #subscription_update
Methods included from Heartbeat
Instance Attribute Details
#session_id ⇒ Object
Returns the value of attribute session_id.
17 18 19 |
# File 'lib/ddp/server/protocol.rb', line 17 def session_id @session_id end |
Instance Method Details
#handle_connect ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ddp/server/protocol.rb', line 23 def handle_connect = if ['msg'] == 'connect' && ['version'] == DDP_VERSION handle_session() else ('msg' => 'failed', 'version' => DDP_VERSION) close end end |
#handle_established ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ddp/server/protocol.rb', line 42 def handle_established loop do @message = next if handle_heartbeat next if handle_data next if handle_rpc break end close end |
#handle_session(message) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ddp/server/protocol.rb', line 34 def handle_session() @session_id = ['session'] || new_session_id ('msg' => 'connected', 'session' => session_id) handle_established end |
#new_session_id ⇒ Object
19 20 21 |
# File 'lib/ddp/server/protocol.rb', line 19 def new_session_id SecureRandom.hex end |