Tag: 动作电缆

具有多个Devise模型的Actioncable身份validation

我目前正在实现两个Devise模型之间的聊天。 Client和Professionnel 。 目前工作正常,但我只有一个渠道:每个客户或专业人员都会收到来自所有客户和所有专业人士的所有消息。 显示很好,但是观看他们的AJAX流的人可以看到每个不适合他们的私人消息。 根据这个主题http://www.thegreatcodeadventure.com/rails-5-action-cable-with-multiple-chatroom-subscriptions/这被称为单一责任原则 所以我试图创建“子流”,以便向正确的用户广播。 我的第一步是使用Devise进行authing。 我正在使用经典: 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.email end protected def find_verified_user if verified_user = env['warden'].user verified_user else reject_unauthorized_connection end end end end 这就是出现问题的地方:当客户端登录时,Actioncable不会创建连接: Started GET “/cable” for 127.0.0.1 at 2018-04-16 22:30:28 +0200 Started GET “/cable/” [WebSocket] for […]

Rails 5 – 如何以实时方式发送通知?

在rails 5中,我试图以实时方式发送通知。 我已经提到了http://jameshuynh.com/rails/react%20js/chat/2017/07/30/build-chat-using-react-js-and-rails-action-cable/ 但我已经有一些方法也会这样做。 根据此方法,通知应基于user_id动态发送。 甚至频道取决于user_id。 在react,header.jsx文件中, import ActionCable from ‘actioncable’; export default class Header extends React.Component { cable = ActionCable.createConsumer(‘ws://localhost:3000/cable’); componentDidMount() { HttpService.get(‘/api/v1/notifications’, this.getNotificationsSuccess); let that = this; this.cable.subscriptions.create(“NotificationsChannel”, { user_id: this.state.currentUser.id, connected: function () { // Timeout here is needed to make sure Subscription // is setup properly, before we do any actions. […]

如何从服务器终止对actioncable频道的订阅?

有没有办法从服务器端(控制器)终止对任何特定使用者的特定通道的订阅,以便可以调用我的咖啡脚本文件中的断开连接回调?

如何在Action电缆中关闭连接?

如何在Action电缆(导轨5)中断开客户端? 我希望用户完全断开连接(类似于他关闭标签时)。

ActionCable未接收数据

我使用ActionCable创建了以下内容,但无法接收任何正在广播的数据。 评论频道 : 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”) } }); 它连接正常,我可以在日志中看到以下内容: CommentsChannel is streaming from comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x 然后我广播到那个流: ActionCable.server.broadcast “comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x”, { test: ‘123’ } 问题是永远不会调用received函数。 难道我做错了什么? 注意:我正在使用actioncable npm包从BackboneJS应用程序进行连接。

通过Actioncable使用群聊查找与聊天室关联的消息用户的图像

对基本问题道歉。 我设法遵循教程,并在SO社区的帮助下设法与Action Cable建立群聊,并学习了这样做的负担。 但是,我正在尝试使用特定的html页面 – 与current_users Chatrooms相关联的Messaging User的图像。 我已经能够拉出与当前用户相关的聊天室以及这些聊天室中提供的最后一条消息。 我试过以下但这只给了我当前聊天室中我的消息用户的图像。 我在下面列出了所有相关代码。 show.html.erb(在我的聊天室html文件夹中) Chatroom.rb class Chatroom {where(direct_message: false) } scope :direct_messages, ->{ where(direct_message: true) } def self.direct_message_for_users(users) user_ids = users.map(&:username).sort name = “#{user_ids.join(” and “)}” if chatroom = direct_messages.where(name: name).first chatroom else chatroom = new(name: name, direct_message: true) chatroom.users = users chatroom.save chatroom end end end […]

validationActionCable连接

我找到了一个很棒的ActionCablegem,这是SPA的一个很好的解决方案。 我想只发送html , css和js资产,所有其他连接都将通过ActionCable实现。 交换字符串或整数并不困难,但我如何通过ActionCable登录?

uninitialized constant> ActionCable :: Server :: Configuration :: ApplicationCable

当我运行服务器时,它的抛出错误显示在下面的日志中。 我google了很多但没有理由支持它。 有人请说清楚。 的Gemfile source ‘https://rubygems.org’ # Bundle edge Rails instead: gem ‘rails’, github: ‘rails/rails’ gem ‘rails’, ‘>= 5.0.0.beta1’, ‘ 0.10.0.rc1’ group :development, :test do gem ‘byebug’ end gem ‘puma’ group :development do gem ‘spring’ end 日志: /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/configuration.rb:15:in `initialize’: uninitialized constant ActionCable::Server::Configuration::ApplicationCable (NameError) from /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `new’ from /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `block in ‘ from /home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:72:in `block in […]