Pusher 未捕获触发事件,因为从 2018 年 9 月 6 日起 Laravel 中 TLS 发生了变化

Pusher is not catching the triggered event since there is a change of TLS from september 6, 2018 in Laravel

Pusher 没有捕捉到触发事件,因为从 2018 年 9 月 6 日起 TLS 发生了变化。 它没有在控制台上给出一个错误,当我打开包含推送器客户端 JavaScript 的页面时,它显示通道已连接到推送器服务器但是当我触发其中任何一个时它既不响应也不给出任何错误。只是它根本不调用绑定事件回调。 这是我包含的缩小 pusher.js。

<script src="https://js.pusher.com/4.3/pusher.min.js"></script>

这是客户端JS绑定事件代码。

var notificationsWrapper   = $('.dropdown-notifications');
var notificationsToggle    = notificationsWrapper.find('a[data-toggle]');
var notificationsCountElem = notificationsToggle.find('i[data-count]');
var notificationsCount     = parseInt(notificationsCountElem.data('count'));
var notifications          = notificationsWrapper.find('ul.dropdown-menu');

if (notificationsCount <= 0) {
  notificationsWrapper.hide();
}

// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('AppKey', {
  cluster: 'ap2',
  forceTLS: true
});
// Subscribe to the channel we specified in our Laravel Event
var channel = pusher.subscribe('subscribed');
channel.bind('pusher:subscription_succeeded', function(members) {
    console.log('subscribed successful') ;
});
channel.bind('pusher:subscription_error', function(status) {
    console.log('subscribed error: '+ status) ;
});
channel.bind('theEvent', function(data) {
  var existingNotifications = notifications.html();
  var avatar = Math.floor(Math.random() * (71 - 20 + 1)) + 20;
  var newNotificationHtml = `
    <li class="notification active">
        <div class="media">
          <div class="media-left">
            <div class="media-object">
              <img src="https://api.adorable.io/avatars/71/`+avatar+`.png" class="img-circle" alt="50x50" style="width: 50px; height: 50px;">
            </div>
          </div>
          <div class="media-body">
            <strong class="notification-title">`+data.type+`</strong>
            <!--p class="notification-desc">Extra description can go here</p-->
            <div class="notification-meta">
              <small class="timestamp">`+data.date_time+`</small>
            </div>
          </div>
        </div>
    </li>
  `;
  notifications.html(newNotificationHtml + existingNotifications);
  notificationsCount += 1;
  notificationsCountElem.attr('data-count', notificationsCount);
  notificationsWrapper.find('.notif-count').text(notificationsCount);
  notificationsWrapper.show();

  $.playSound('/notification/notification.mp3') ;
});

这是我在 laravel 控制器中调用触发器的地方。

        $pusher = HomeController::getPusher() ;
        $pusher->trigger('subscribed', 'theEvent', $callBack);

这两行在一个函数中,如果在控制器响应视图之前调用并执行特定路由,则调用该函数。并且 Pusher 实例是使用 Home Controller 的引用创建的。这些路由功能和推送器功能都在家庭控制器中。

public function getPusher() {
    $options = array(
        'cluster' => 'ap2',
        'useTLS' => true
      );
      $pusher = new Pusher(
        'AppKey',
        'AppSecret',
        'AppId',
        $options
      );

    return $pusher ;
}

如果您像我假设的那样继续使用 encrypted:true,您会遇到同样的问题吗?

我帮助维护这个库并将对此进行调查。与此同时,我们与 TLS 相关的基础设施还没有发生变化——这个变化只是一个变量重命名。同时,您可以使用旧版本的库来避免它。我会尽快回复你!