module Engine2::ActionWebSocketSupport
Public Instance Methods
invoke!(handler)
click to toggle source
Calls superclass method
# File lib/engine2/action.rb, line 203 def invoke! handler if Faye::WebSocket.websocket?(handler.env) ws = Faye::WebSocket.new(handler.env) @ws_methods.each do |method, blk| ws.on(method) do |evt| begin data = method == :message ? JSON.parse(evt.data, symbolize_names: true) : evt action = self.class.new(node, assets, self) result = action.instance_exec(data, ws, evt, &blk) result = {} unless result.is_a?(Hash) result[:meta] = action.meta ws.send! result unless action.meta.empty? rescue Exception => e ws.send! error: {exception: e, method: method} end end end ws.rack_response else super end end
post_run()
click to toggle source
Calls superclass method
# File lib/engine2/action.rb, line 198 def post_run super @invokable = true end
pre_run()
click to toggle source
Calls superclass method
# File lib/engine2/action.rb, line 184 def pre_run super @ws_methods = {} @meta[:websocket] = {options: {}} end
ws_execute(execute)
click to toggle source
# File lib/engine2/action.rb, line 194 def ws_execute execute (@meta[:websocket][:execute] ||= {}).merge! execute end
ws_options(opts)
click to toggle source
# File lib/engine2/action.rb, line 190 def ws_options opts @meta[:websocket][:options].merge! opts end