如何使用 Faye 只通知页面上的特定用户?
我有一个问题。我使用 faye 来更新此页面上所有客户的部分页面。但我很受伤。如何仅针对特定用户更新部分页面。就我而言,我想通知用户有新消息。但我不知道该怎么做。我只知道如何通知某个页面上的所有人。例如,在我的帖子模型中,我创建了js
<% broadcast "/posts/new" do %>
$('#posts_list').prepend('<%= escape_javascript(render(@post)) %>');
$("#posts_list li:first").hide().fadeIn("slow");
<% end %>
和广播功能,
def broadcast(channel, &block)
message = {:channel => channel, :data => capture(&block)}
uri = URI.parse("http://localhost:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end
我也有一个faye客户端和代码
$(function() {
var faye = new Faye.Client('http://localhost:9292/faye');
faye.subscribe("/posts/new", function(data){
eval(data);
});
});
(所有这些都是根据railscast完成的。)
我需要以什么方式思考?提前致谢!
I have a question. I was using faye, for updating part of page for all clients at this page. But I am woundering. How can I make updating part of the page only for specific users. In my case, I want to notify user about new message. But I dont know how to do this. I only know how to notify all people on certain page. For example , in my post model I have create js
<% broadcast "/posts/new" do %>
$('#posts_list').prepend('<%= escape_javascript(render(@post)) %>');
$("#posts_list li:first").hide().fadeIn("slow");
<% end %>
and broadcast function is
def broadcast(channel, &block)
message = {:channel => channel, :data => capture(&block)}
uri = URI.parse("http://localhost:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end
also i had a faye client and code
$(function() {
var faye = new Faye.Client('http://localhost:9292/faye');
faye.subscribe("/posts/new", function(data){
eval(data);
});
});
(all this was done according to the railscast.)
In what way I need to think? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决这个问题的方法。 Gem私人酒吧(https://github.com/ryanb/private_pub)
帮助做到这一点。
每个用户都有布局
以及何时有人发送消息。在action.js(在我的例子中-create.js)中,我这样做了
,这对我来说非常有用。
I found the way to solve this problem. Gem private pub(https://github.com/ryanb/private_pub)
help to do this.
Each user have in layout
and when somebody sends message. In action.js( in my case - create.js) I did this
and this works great for me.