从Pusher注销时,广播接收器不起作用

时间:2019-04-07 17:43:25

标签: laravel firebase-realtime-database push-notification broadcastreceiver pusher

我确实使用pusher在我的应用程序中实现了广播通知。它在现场。它工作正常,但问题是当我从pusher注销或关闭pusher窗口时无法收到通知。如果我再次登录pusher,则通知工作。

在刀片中:

Echo.channel('NotificationChannel')
  .listen('NotificationEvent', (e) => {
      if( {{Auth::user()->id}} == e.to_doctor_notification.id){
        toastr.success('You have a new patient request.', e.to_doctor_notification.name, {timeOut: 50000, progressBar: true, positionClass: 'toast-bottom-left', closeButton: true, newestOnTop: true, extendedTimeOut: 100000})
      };
  });

在控制器中:

broadcast(new NotificationEvent($to_doctor_notification));

在NotificationEvent中:

public function broadcastOn(){
    return new Channel('NotificationChannel');
}

在bootstrap.js中:

import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'app-key',
    cluster: 'ap2',
    encrypted: true
});

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我包含的JavaScript文件过多。那为什么它不起作用。

我包括推入式链接 this is pusher link

这些是“通知”接收的代码,其中的页面要查看该通知。

<script>
      var pusher = new Pusher('app-key', {
      cluster: 'ap2',
      forceTLS: true
     });

var channel = pusher.subscribe('NotificationChannel');
channel.bind('EchoEvent', function(e) {
  if( {{Auth::user()->id}} == e.to_doctor_notification.id){
    toastr.success('You have a new patient request.', e.to_doctor_notification.name, {timeOut: 50000, progressBar: true, positionClass: 'toast-bottom-left', closeButton: true, newestOnTop: true, extendedTimeOut: 100000})
  };
});