小编opl*_*pla的帖子

ActionCable:从前端手动关闭连接

我不能手动关闭我的套接字.它仅在我关闭浏览器中的选项卡时退出.

Finished "/cable/" [WebSocket] for 127.0.0.1 at 2016-10-29 16:55:49 +0200
Run Code Online (Sandbox Code Playgroud)

但是当我打电话的时候

App.cable.subscriptions.remove(App.subscription)
Run Code Online (Sandbox Code Playgroud)

要么

App.subscription.unsubscribe()
Run Code Online (Sandbox Code Playgroud)

CommunityChannel正在调用方法"unsubscribed" ,但电缆仍然存在,我仍然可以在我的函数"print_socket"中打印它

如何手动关闭连接?

module ApplicationCable
  class Connection < ActionCable::Connection::Base

    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    protected

    def find_verified_user
      if current_user = User.find_by(id: cookies.signed[:user_id])
        current_user
      else
        reject_unauthorized_connection
      end
    end

  end
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-5 actioncable

4
推荐指数
1
解决办法
1123
查看次数