0
我的代碼非常依賴用戶是否在線。用ActionCable保持用戶「在線」
目前我設置ActionCable這樣的:
class DriverRequestsChannel < ApplicationCable::Channel
def subscribed
stream_from "requests_#{current_user.id}"
end
def unsubscribed
current_user.unavailable! if current_user.available?
end
end
現在我會非常喜歡的覆蓋是用戶的,而不是剛進入脫機只是關閉瀏覽器的情況。但是,取消訂閱的問題在於它進行頁面刷新。所以每次刷新頁面時都會觸發unsubscribed
。因此即使他們認爲他們可用,他們也會被視爲不可用。
現在關鍵是可用不是默認的,所以我可以放回去,這是用戶選擇接收請求的東西。
有沒有人有處理這種情況的最佳方法的經驗?