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) 建立的所有连接,无论这些连接运行在哪个服务器上,因为它使用的是所有这些服务器都订阅的内部频道。
默认情况下,服务器发送一个“disconnect”消息,并将“reconnect”标志设置为 true。您可以修改此行为,通过指定 reconnect 选项来覆盖它。
ActionCable.server.remote_connections.where(current_user: User.find(1)).disconnect(reconnect: false)
命名空间
方法
Attributes
| [R] | 服务器 |
类公共方法
new(server) 链接
来源: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/remote_connections.rb, line 34 def initialize(server) @server = server end
实例公共方法
where(identifier) 链接
来源: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/remote_connections.rb, line 38 def where(identifier) RemoteConnection.new(server, identifier) end