是否可以将未订阅的频道“名称”返回给未订阅的方法?
当用户取消订阅频道时(由于断开连接或导航离开),我需要确保客户端标志设置为空状态。我已经创建了一个清理方法,但是我无法找出清理消息应该发送到哪个频道。因为我无法获取取消订阅的方法是从哪个频道调用的。
class ConversationChannel < ApplicationCable::Channel
def follow(data)
stop_all_streams
conversation = Conversation.find(data['conversation_id'])
if conversation.is_participant?(current_user)
stream_from "conversation:#{data['conversation_id']}"
end
end
def unsubscribed
clear_typing
end
...
def clear_typing
# need way to find out conversation_id of the unsubscribed stream
ActionCable.server.broadcast "conversation:#{data['conversation_id']}", {id: current_user.id, typing: false}
end
end