RuntimeError-无法找到带有标识符的订阅:当iOS应用尝试发送消息时

问题描述

我正在使用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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...