Pusher:我的赛事没有为推杆测试回调

时间:2017-10-03 13:53:38

标签: javascript php laravel

所以我试图通过这个测试获得我创建的每个对象,在不刷新页面的情况下进行广播。 这是我们实例化推送器并为UserHasRegistered绑定事件的js:               

            // Enable pusher logging - don't include this in production
            Pusher.logToConsole = true;
            (function() {
                var pusher = new Pusher('3c50750503376de6d201', {
                    cluster: 'eu',
                    encrypted: true
                });
                var channel = pusher.subscribe('test');
                channel.bind('App\\Events\\UserHasRegistered', function(data) {
                    console.log(data);
                });
            })();
            </script>

这是我广播注册用户名的路线,我也提到了对推送器的绑定。

         Route::get('broadcast', function(){
              $name = Request::input('name');
              event(new UserHasRegistered($name));
              return 'Done';
              });

事件Listener正在运行,我得到了env设置以及broadcast.php,但这就是我得到的:

  Pusher : State changed : initialized -> connecting  pusher.min.js:8:2561
Pusher : Connecting : {"transport":"ws","url":"wss://ws-eu.pusher.com:443             /app/3c50750503376de6d201?protocol=7&client=js&version=4.1.0&flash=false"}       pusher.min.js:8:2561
Pusher : State changed : connecting -> connected with new socket ID 123754.768449  pusher.min.js:8:2561
Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"test"}}  pusher.min.js:8:2561
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"test"}        pusher.min.js:8:2561
Pusher : No callbacks on test for pusher:subscription_succeeded     pusher.min.js:8:2561

1 个答案:

答案 0 :(得分:1)

您应该同时使用两者。要捕获错误并订阅您的频道:

channel.bind('pusher:subscription_succeeded', function(members) {
    // alert('successfully subscribed!');
 });

 channel.bind("App\\Events\\UserHasRegistered", function(data) {
     console.log(data);
 });

因为您可以绑定多个事件。