ruby-on-rails – ActionCable:从前端手动关闭连接

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

Finished "/cable/" [WebSocket] for 127.0.0.1 at 2016-10-29 16:55:49 +0200

但是当我打电话的时候

App.cable.subscriptions.remove(App.subscription)

要么

App.subscription.unsubscribe()

正在调用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

解决方法

App.cable.subscriptions.remove(App.subscription)将取消订阅“CommunityChannel”,但不会关闭您的连接,

如果你想断开连接,那么就这样做:

App.cable.disconnect()

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...