Class: RocketChat::Realtime::Dispatcher
- Inherits:
-
Object
- Object
- RocketChat::Realtime::Dispatcher
- Extended by:
- Forwardable
- Defined in:
- lib/rocket_chat/realtime/dispatcher.rb
Overview
Message Dispatcher
Constant Summary collapse
- HANDLERS =
{ # Heartbeat 'ping' => ->(dispatcher, _) { dispatcher.driver.text({ 'msg': 'pong' }.to_json) }, # RPC 'result' => Handlers::Result, # Subscription 'ready' => Handlers::Ready, 'changed' => Handlers::Changed }.freeze
Instance Attribute Summary collapse
- #client ⇒ Object readonly
Instance Method Summary collapse
-
#dispatch(event) ⇒ Boolean
Dispatch messages.
-
#dispose ⇒ Object
Dispose.
-
#initialize(client) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(client) ⇒ Dispatcher
Returns a new instance of Dispatcher.
44 45 46 47 48 |
# File 'lib/rocket_chat/realtime/dispatcher.rb', line 44 def initialize(client) @client = client driver.on(:message, &method(:dispatch)) end |
Instance Attribute Details
#client ⇒ Object (readonly)
39 40 41 |
# File 'lib/rocket_chat/realtime/dispatcher.rb', line 39 def client @client end |
Instance Method Details
#dispatch(event) ⇒ Boolean
Dispatch messages
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rocket_chat/realtime/dispatcher.rb', line 57 def dispatch(event) = JSON.parse(event.data) handler = HANDLERS[.fetch('msg', nil)] if handler handler.call(self, ) else logger.debug("No handler found for: #{}") false end rescue JSON::ParserError # nope end |
#dispose ⇒ Object
Dispose
Clear references
75 76 77 |
# File 'lib/rocket_chat/realtime/dispatcher.rb', line 75 def dispose @client = nil end |