Art*_*huk 20 ruby-on-rails actioncable
我使用ActionCable创建了以下内容,但无法接收任何正在广播的数据.
评论频道:
class CommentsChannel < ApplicationCable::Channel
def subscribed
comment = Comment.find(params[:id])
stream_for comment
end
end
Run Code Online (Sandbox Code Playgroud)
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")
}
});
Run Code Online (Sandbox Code Playgroud)
它连接正常,我可以在日志中看到以下内容:
CommentsChannel is streaming from comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x
Run Code Online (Sandbox Code Playgroud)
然后我广播到那个流:
ActionCable.server.broadcast "comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x", { test: '123' }
Run Code Online (Sandbox Code Playgroud)
问题是received永远不会调用该函数.难道我做错了什么?
注意:我正在使用actioncablenpm包从BackboneJS应用程序连接.
Art*_*huk 40
从改变电缆适配器async,以redis在config/cable.yml固定对我来说.不知道为什么async不工作.
| 归档时间: |
|
| 查看次数: |
6505 次 |
| 最近记录: |