我正在创建一个私人频道,将在该频道上发送长时间运行的操作的结果。我的浏览器控制台中有以下内容:
Pusher : State changed : initialized -> connecting
rt_cli...?body=1 (line 5)
Pusher : Connecting : {"transport":"ws","url":"ws://ws-eu.pusher.com:80/app/xxxxxxxxxxxxx?protocol=6&client=js&version=2.1.2&flash=false"}
rt_cli...?body=1 (line 5)
Pusher : State changed : connecting -> connected
rt_cli...?body=1 (line 5)
POST http://localhost:3000/pusher/auth
pusher.min.js (line 111)
Connected to Pusher!
common.js?body=1 (line 56)
Pusher : Event sent : {"event":"pusher:subscribe","data":{"auth":"179bfeac81d16e6ae36f:81fa74052368dac232d70146d2f2d343f3d4ce5befc34bce43673a9e6ceaa38a","channel":"private-user-channel-11"}}
rt_cli...?body=1 (line 5)
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"private-user-channel-11"}
rt_cli...?body=1 (line 5)
Pusher : No callbacks on private-user-channel-11 for pusher:subscription_succeeded
客户端连接如下所示:
$(document).ready(function() {
Pusher.host = 'ws-eu.pusher.com';
Pusher.sockjs_host = 'sockjs-eu.pusher.com';
pusher = new Pusher("#{ ENV["PUSHER_APP_KEY"] }", {cluster: "eu"});
var channel = pusher.subscribe("private-user-channel-11");
// Some useful debug msgs
pusher.connection.bind('connecting', function() {
clog("connecting to pusher");
});
pusher.connection.bind('connected', function() {
clog('Connected to Pusher!');
});
pusher.connection.bind('failed', function() {
clog('Connection to Pusher failed :(');
});
channel.bind('subscription_error', function(status) {
clog('Pusher subscription_error');
});
channel.bind("ninja", function(e) {
console.log(e);
});
});
从我的工作进程中,我触发了这样的事件:
Pusher.trigger s_channel_name, "ninja", {"message" => "whatever"}
问题是,我的页面加载,脚本执行,但在浏览器中我没有收到消息。但是,如果我刷新页面(并在浏览器控制台中保留日志,我会看到收到了消息)。另外,我注意到如果我在两个不同的浏览器中登录,并在这两个浏览器中保持页面打开,未刷新的浏览器将实时接收事件。这使我相信触发的浏览器(即使是间接请求,也被排除在消息的收件人之外。有没有办法向连接到私人频道的所有用户广播?另外,如果我触发从 Rails 控制台手动操作事件,它会立即出现(无需刷新浏览器)。
编辑:看起来我的工作人员在浏览器加载页面之前完成了他的工作,并且消息丢失了。很抱歉认为问题出在其他地方。