'RuntimeError - Unable to find subscription with identifier: when ios app try to send a message
I am using WebSocket for comments on a post. ios user subscribe to the comment_channel
and I got confirmation that the user successfully subscribed to comment_channel.
[ActionCable] [23] CommentRoomsChannel is transmitting the subscription confirmation
[ActionCable] [23] CommentRoomsChannel is streaming from comments_291
But the issue is when the user tries to comment I get this error.
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'
I have added delay but this error even occurs when users try to comment for the first time.
here's my code:
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
this error only occurs when the ios user tries to comment, the same code is working with android.
Solution 1:[1]
I resoved the issue by removing the parameter from the identifier. so before the issue my command was
{"identifier"=>"{\"channel\":\"CommentRoomsChannel\",\"post_id\":\"291\"}"
after removing parameter
{"identifier"=>"{\"channel\":\"CommentRoomsChannel\"}"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jasjeet Singh |