186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/engine2/action.rb', line 186
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
|