class WSDirector::Protocols::ActionCable
ActionCable
protocol
Constants
- PING_IGNORE
- WELCOME_MSG
Public Instance Methods
init_client(**options)
click to toggle source
Add ping ignore and make sure that we receive Welcome message
Calls superclass method
# File lib/wsdirector/protocols/action_cable.rb, line 11 def init_client(**options) options[:ignore] ||= [PING_IGNORE] super(**options) receive("data" => WELCOME_MSG) end
perform(step)
click to toggle source
# File lib/wsdirector/protocols/action_cable.rb, line 34 def perform(step) identifier = extract_identifier(step) action = step.delete("action") raise Error, "Action is missing" unless action data = step.fetch("data", {}).merge(action: action).to_json client.send({command: "message", data: data, identifier: identifier}.to_json) end
receive(step)
click to toggle source
Calls superclass method
# File lib/wsdirector/protocols/action_cable.rb, line 45 def receive(step) return super unless step.key?("channel") identifier = extract_identifier(step) message = step.fetch("data", {}) super("data" => {"identifier" => identifier, "message" => message}) end
receive_all(step)
click to toggle source
Calls superclass method
# File lib/wsdirector/protocols/action_cable.rb, line 53 def receive_all(step) messages = step["messages"] return super if messages.nil? || messages.empty? messages.each do |msg| next unless msg.key?("channel") identifier = extract_identifier(msg) msg["data"] = {"identifier" => identifier, "message" => msg["data"]} end super end
subscribe(step)
click to toggle source
# File lib/wsdirector/protocols/action_cable.rb, line 19 def subscribe(step) identifier = extract_identifier(step) client.send({command: "subscribe", identifier: identifier}.to_json) begin receive( "data" => {"type" => "confirm_subscription", "identifier" => identifier} ) rescue UnmatchedExpectationError => e raise unless /reject_subscription/.match?(e.message) raise UnmatchedExpectationError, "Subscription rejected to #{identifier}" end end
Private Instance Methods
extract_identifier(step)
click to toggle source
# File lib/wsdirector/protocols/action_cable.rb, line 69 def extract_identifier(step) channel = step.delete("channel") step.fetch("params", {}).merge(channel: channel).to_json end