是否有可能将未订阅的频道“名称”返回给未订阅的方法?客户端取消订阅频道
当用户取消订阅频道(由于断开连接或导航离开)时,我需要确保客户端标志设置为空状态。我已经创建了一个清理方法,但是我找不到清理消息应该发送到哪个通道..因为我无法获得从哪个通道调用未订阅的方法。
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
我更新了我的问题,因为我想我可能没有问得很对。我想我也找到了解决方案..正在研究stop_all_streams方法的源代码,并意识到'streams'是ChannelClass中的一个可用变量 – ethayer