1
我用戶進行身份驗證ActionCable這樣的:Actioncable連接的用戶列表
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.name
end
protected
def find_verified_user
if verified_user = User.find_by(id: cookies.signed[:user_id])
verified_user
else
reject_unauthorized_connection
end
end
end
end
是否有可能獲得連接的用戶列表?我谷歌搜索,但只發現這個計算器的問題:first,second
看來,重啓作用電纜服務器時,connected_nodes不會重啓。任何解決方法? – cisolarix
可能會添加一個初始化程序來清除redis緩存connected_nodes? – NullVoxPopuli
我相信當一個特定用戶連接多個瀏覽器窗口時,這也會失敗。當用戶關閉一個窗口時,即使它們仍然從另一個窗口連接,它們將從ConnectedList中完成刪除(因爲用戶列表是使用一個集合進行跟蹤的)。 – odonnellt