Class: XRBP::WebSocket::Plugins::CommandDispatcher
- Inherits:
-
MessageDispatcher
- Object
- PluginBase
- MessageDispatcher
- XRBP::WebSocket::Plugins::CommandDispatcher
- Defined in:
- lib/xrbp/websocket/plugins/command_dispatcher.rb
Overview
Dispatch commands (based on message dispatcher)
Constant Summary
Constants inherited from MessageDispatcher
MessageDispatcher::DEFAULT_TIMEOUT
Instance Attribute Summary
Attributes inherited from MessageDispatcher
Attributes inherited from PluginBase
Instance Method Summary collapse
Methods inherited from MessageDispatcher
#cancel_all_messages, #cancel_message, #closed, #initialize, #message, #opened, #parsing_plugins, #try_next, #unlock!
Methods inherited from PluginBase
Constructor Details
This class inherits a constructor from XRBP::WebSocket::Plugins::MessageDispatcher
Instance Method Details
#added ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xrbp/websocket/plugins/command_dispatcher.rb', line 11 def added super plugin = self connection.define_instance_method(:cmd) do |cmd, &bl| return next_connection.cmd cmd, &bl if self.kind_of?(MultiConnection) cmd = Command.new(cmd) unless cmd.kind_of?(Command) msg(cmd, &bl) end end |
#match_message(msg) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/xrbp/websocket/plugins/command_dispatcher.rb', line 24 def (msg) begin return nil if msg.data == "" parsed = JSON.parse(msg.data) rescue => e return nil end id = parsed['id'] msg = .find { |msg| msg.kind_of?(Command) && msg.id == id } return nil unless msg [msg, parsed] end |