actioncable

Action Cable not working after binding with ip

和自甴很熟 提交于 2019-12-05 20:24:03
问题 I have implemented action cable of rails-5 in my system and it's work fine on localhost , but when i tried to bind with ip it's give below error message. WebSocket connection to 'ws://192.168.1.46:3002/cable' failed: Error during WebSocket handshake: Unexpected response code: 404 and in terminal log Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) I have made changes on my development.rb as like config.action_cable.url = "ws://192.168.1

Rails Devise Action Cable

不想你离开。 提交于 2019-12-05 18:55:08
问题 I'm trying to get Action Cable working with Devise. module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :current_user def connect self.current_user = find_verified_user logger.add_tags 'ActionCable', current_user.name end protected def find_verified_user verified_user = User.find_by(id: cookies.signed['user.id']) if verified_user && cookies.signed['user.expires_at'] > Time.now verified_user else reject_unauthorized_connection end end end end If an user is

action cable subscribing locally, but not on heroku

浪尽此生 提交于 2019-12-05 16:56:45
问题 I've been trying everything I can find online, and nothing is working. Hoping some fresh eyes will see the issue. This is my first time using ActionCable, and everything works great locally, but when pushing to heroku. my logs do not show any actioncable subscriptions like my dev server: [ActionCable] [email@email.com] MsgsChannel is streaming from msg_channel_34 and when sending a message, I do see [ActionCable] Broadcasting to msg_channel_34: but they are not appending, which I'm guessing

How to close connection in Action cable?

浪子不回头ぞ 提交于 2019-12-05 12:59:15
How to disconnect a client in Action cable (rails 5)? I would like the user to be completely disconnected (similar to when he closes the tab). You can use the unsubscribe() function: App.example = App.cable.subscriptions.create(..); App.example.unsubscribe(); I found this inside /var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/remote_connections.rb If you need to disconnect a given connection, you can go through the RemoteConnections. You can find the connections you're looking for by searching for the identifier declared on the connection. For example: module ApplicationCable class

How to terminate subscription to an actioncable channel from server?

不羁的心 提交于 2019-12-05 06:27:45
Is there a way to terminate the subscription to a particular channel for any particular consumer from the server side (controller) so that disconnected callback in my coffee script file can be invoked? http://api.rubyonrails.org/classes/ActionCable/Channel/Base.html#class-ActionCable::Channel::Base-label-Rejecting+subscription+requests class ChatChannel < ApplicationCable::Channel def subscribed @room = Chat::Room[params[:room_number]] reject unless current_user.can_access?(@room) end end Before calling reject you can also inform the subscriber of the reject's reason: class ChatChannel <

Disable rails log for ActionCable events

人盡茶涼 提交于 2019-12-05 00:06:59
In development environment, rails logger logs all ActionCable events which is sometimes annoying (for my project, every now and then it's transmitting messages and log tail is running like wild horse). What is an efficient way to suppress all event logs from ActionCable? Also, how can I suppress some specific ActionCable events? To completely disable logging from ActionCable you should configure ActionCable to use logger that do nothing ActionCable.server.config.logger = Logger.new(nil) Same here, finally I found a solution. You should override a code in /app/channels/application_cable/channel

How can I test ActionCable channels using RSpec?

余生颓废 提交于 2019-12-04 17:52:03
问题 I am wondering about testing ActionCable channels. Let's say I have the following chat channel: class ChatChannel < ApplicationCable::Channel def subscribed current_user.increment!(:num_of_chats) stream_from "chat_#{params[:chat_id]}" stream_from "chat_stats_#{params[:chat_id]}" end end The subscribed method updates the db and defines two streams to be broadcasted across the channel, but the details are not very important since my question is a more general one: How can I set up a test to

Deploying Ruby on Rails app to Heroku while using Action Cable (Puma port listening)

笑着哭i 提交于 2019-12-04 14:02:41
I have got Action Cable working in a local host environment and in this situation I start the Puma server using a simple file containing # /bin/bash bundle exec puma -p 28080 cable/config.ru Once this happens the puma server starts and is listening to this 28080 port and the port the local server is running on. Through hunting online I couldn't find a place that would tell me a way to emulate this on heroku or a way to have my server always start on the same port (though I don't know if that would give me the desired result either) I have a javascript file set up to create a consumer related

how to send message to all client except sender in rails/actioncable?

那年仲夏 提交于 2019-12-04 10:43:17
问题 in socket.io, you can send message to all client except sender like: socket.broadcast.emit('user connected'); but in rails/actioncable, how to do that? class BoardChannel < ApplicationCable::Channel def subscribed stream_from "board:#{params[:board]}" end def speak # client will call @perform('speak') result = do_something() # how to send 'result' to all client except sender? end end 回答1: Using jobs, you can make this with the logic in a partial. In your model after create a record, call the

What can be the reason of “Unable to find subscription with identifier” in Rails ActionCable?

喜欢而已 提交于 2019-12-04 08:37:20
I'm building a messenger application using Rails 5.0.0.rc1 + ActionCable + Redis. I've single channel ApiChannel and a number of actions in it. There are some "unicast" actions -> ask for something, get something back, and "broadcast" actions -> do something, broadcast the payload to some connected clients. From time to time I'm getting RuntimeError exception from here: https://github.com/rails/rails/blob/master/actioncable/lib/action_cable/connection/subscriptions.rb#L70 Unable to find subscription with identifier (...) . What can be a reason of this? In what situation can I get such