How to close connection in Action cable?

后端 未结 5 480
时光取名叫无心
时光取名叫无心 2021-01-12 10:59

How to disconnect a client in Action cable (rails 5)? I would like the user to be completely disconnected (similar to when he closes the tab).

5条回答
  •  一生所求
    2021-01-12 11:39

    My work around was to create a new route just for disconnect.

    def disconnection
        ActionCable.server.remote_connections.where(connected_user: user_params['email']).disconnect
    
       render json: {}, status: 200 
    end
    

    The client side would have to call the endpoint... something like

    PUT  /api/cable/disconnection
    

提交回复
热议问题