Action Cable 远程连接
如果您需要断开某个连接,您可以通过 RemoteConnections
进行操作。您可以通过搜索连接上声明的标识符来查找您要查找的连接。例如
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
....
end
end
ActionCable.server.remote_connections.where(current_user: User.find(1)).disconnect
这将断开为 User.find(1)
建立的所有连接,包括所有服务器上运行的所有机器,因为它使用所有这些服务器都订阅的内部通道。
默认情况下,服务器会发送一个带有“reconnect”标志设置为 true 的“disconnect”消息。您可以通过指定 reconnect
选项来覆盖它
ActionCable.server.remote_connections.where(current_user: User.find(1)).disconnect(reconnect: false)
命名空间
方法
属性
[R] | server |
类公共方法
new(server) 链接
来源: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/remote_connections.rb, line 32 def initialize(server) @server = server end
实例公共方法
where(identifier) 链接
来源: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/remote_connections.rb, line 36 def where(identifier) RemoteConnection.new(server, identifier) end