How to send WebSocket request status to ActionCable

Is there a way to send request status to a client in ActionCable Channels?

For example, if the data sent is invalid (or some unknown exception was raised), I want the error text in the response message, otherwise send 'status: ok'. Now I have a client-side subscriber method to perform that returns true in almost all circumstances, as we can see from the source code ( github ):

send: (data) ->
  if @isOpen()
    @webSocket.send(JSON.stringify(data))
    true
  else
    false

In websocket-rails gem there were methods for this: trigger_failure and trigger_success ,

+4
source share

Source: https://habr.com/ru/post/1655552/


All Articles