actioncable

ActionCable: One channel per user

China☆狼群 提交于 2019-12-04 07:22:57
I am working on notifications for my rails app. There is User model and controller and Like model associated to User with a User has many Likes association. The idea is, if a user likes the profile of another user, owner of the profile will get a live notification. This is my app for understanding ActionCable. I studied the cable api , pub-sub was new to me. I was able to make successful communication through a single channel, and also successfully used the authorization . But, still I don't understand how to use single channel per user (dynamically generated channel), so that message posted

Rails 5 ActionCable is not returning upgrade headers with status 101 Upgrade response

纵然是瞬间 提交于 2019-12-04 03:57:03
问题 EDIT: Shown at end, found that upgrade headers were actually created. I'm working from the action-cable-example codebase, trying to build a WebSocket app. The "Chatty" application, which depends upon the browser client provided in the app, works fine. But, I am not going to use that client as I need an external IoT connection. As a result, I am trying to implement the ws/wss WebSocket protocols to external non-browser devices and my connection in route.rb is: mount ActionCable.server => '

Action Cable not working after binding with ip

纵然是瞬间 提交于 2019-12-04 02:39:37
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.46:3002/cable" but not succeed. please guide me where i am wrong. tell me if you need extra information,

Capybara not working with action_cable

与世无争的帅哥 提交于 2019-12-03 17:48:00
问题 I'm using the Rails 5 beta 3 with action cable, the integration works fine in development but when I try to run a feature test through capybara, it doesn't seem to hit the channel actions. I'm using Portergeist and configured puma as capybara's server. Also I'm using es5-shim and es6-shim. Has anyone else experienced this or knows any workaround? Thanks! Edit Im using this capybara branch to configure Puma in Capybara Capybara.register_server :puma do |app, port, host| require 'puma' Puma:

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

和自甴很熟 提交于 2019-12-03 06:26:23
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 Using jobs, you can make this with the logic in a partial. In your model after create a record, call the job perform passing the self record. See bellow how pass message to recieved data(at channel) using

ActionCable Not Receiving Data

你离开我真会死。 提交于 2019-12-03 04:52:06
I created the following using ActionCable but not able to receive any data that is being broadcasted. Comments Channel : class CommentsChannel < ApplicationCable::Channel def subscribed comment = Comment.find(params[:id]) stream_for comment end end JavaScript : var cable = Cable.createConsumer('ws://localhost:3000/cable'); var subscription = cable.subscriptions.create({ channel: "CommentsChannel", id: 1 },{ received: function(data) { console.log("Received data") } }); It connects fine and I can see the following in the logs: CommentsChannel is streaming from comments

Send auth_token for authentication to ActionCable

流过昼夜 提交于 2019-12-02 22:53:38
module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :current_user def connect #puts params[:auth_token] self.current_user = find_verified_user logger.add_tags 'ActionCable', current_user.name end end end I don't use web as end point for action cable, so I want to use auth_token for authentication. By default action cable use session user id for authentication. How to pass params to connect method? Pierre Fraisse I managed to send my authentication token as a query parameter. When creating my consumer in my javascript app, I'm passing the token in the cable

Consuming Rails 5 ActionCable

随声附和 提交于 2019-12-01 13:06:16
问题 I'm playing around with the new ActionCable feature. Is there a way of communicating with the ActionCable server using say socket.io or from an application using React or ReactNative? Perhaps I'm confusing the correct use of ActionCable and it is not intended to be used as a let's say API replacement and it is meant to be used as a supporting front end technology for the same app. Any good example or guide to use ActionCable as standalone WS server would be appreciated if this is possible.

Actioncable connected users list

戏子无情 提交于 2019-12-01 10:32:15
I'm authenticating users in ActionCable like this: 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 if verified_user = User.find_by(id: cookies.signed[:user_id]) verified_user else reject_unauthorized_connection end end end end Is it possible to get connected users list ? I googled but found only this stackoverflow questions: first , second Ya kinda have to roll your own user-tracking. The important bits are

Actioncable connected users list

痴心易碎 提交于 2019-12-01 08:41:51
问题 I'm authenticating users in ActionCable like this: 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 if verified_user = User.find_by(id: cookies.signed[:user_id]) verified_user else reject_unauthorized_connection end end end end Is it possible to get connected users list ? I googled but found only this