Question

I'm creating a private channel on which the result of a longish running operation will be sent. I have the following in my browser's console:

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

The client side connection looks like this:

  $(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);
      });
    });

From my worker process, I'm triggering the event like this:

Pusher.trigger s_channel_name, "ninja", {"message" => "whatever"}

The thing is, my page loads, and the script executes, but in the browser I don't receive the message. If, however, I refresh the page ( and preserve the logs in the browser console, I see that the message gets received ). Also, I notice that if I login in two different browsers, and keep the page open in both of them, the browser which is not refreshed will receive the event in real time. This leads me to believe that the browser that triggers ( even indirecectly the request, is excluded from the recipients of the message. Is there a way to broadcast to all the users connected to a private channel? Also, it seems that if I trigger the event manually from the Rails console, it appears instantly ( without having to refresh browser ).

EDIT: It looks like my worker finished his job before the browser could load the page, and the message got lost. Sorry for thinking the problem lay elsewhere.

Was it helpful?

Solution

The problem was that the worker triggered the message before the page finished loading, and I could not react to the event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top