问题描述
我正在使用WebSocket在帖子上发表评论。 ios用户订阅了comment_channel
,我确认该用户成功订阅了comment_channel。
[ActionCable] [23] CommentRoomsChannel is transmitting the subscription confirmation
[ActionCable] [23] CommentRoomsChannel is streaming from comments_291
Could not execute command from ({"identifier"=>"{\"channel\":\"CommentRoomsChannel\",\"post_id\":\"291\"}","command"=>"message","data"=>"{\"description\":\"Aaaa\",\"post_id\":\"291\"}"}) [RuntimeError - Unable to find subscription with identifier: {"channel":"CommentRoomsChannel","post_id":"291"}]: /home/ubuntu/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.2/lib/action_cable/connection/subscriptions.rb:74:in `find' | /home/ubuntu/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.2/lib/action_cable/connection/subscriptions.rb:55:in `perform_action' | /home/ubuntu/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.2/lib/action_cable/connection/subscriptions.rb:19:in `execute_command' | /home/ubuntu/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.2/lib/action_cable/connection/base.rb:87:in `dispatch_websocket_message' | /home/ubuntu/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.2/lib/action_cable/server/worker.rb:59:in `block in invoke'
我增加了延迟,但是当用户首次尝试发表评论时,甚至会发生此错误。
这是我的代码:
class CommentRoomsChannel < ApplicationCable::Channel
def subscribed
stream_from "comments_#{params[:post_id]}"
end
def unsubscribed
stop_all_streams
end
def receive(data)
post = Post.find_by(id: data["post_id"])
post_data = {
id: comment['id'],post_id: comment['post_id'],user_id: comment['user_id'],description: comment['description'].to_s,user: {
id: current_user['id'],first_name: current_user['first_name'],last_name: current_user['last_name'],username: current_user['username'],is_hide_name: current_user['is_hide_name'],profile_image: current_user['profile_image']
}
}
comment = current_user.comments.create!(description: data["description"],post_id: data["post_id"])
ActionCable.server.broadcast "comments_#{data['post_id']}",post_data.as_json
NotificationService.new(post.user_id,current_user.id,2,data['post_id'].to_i).call unless post.user_id == current_user.id
end
end
此错误仅在ios用户尝试发表评论且同一代码在android上运行时发生。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)