Я пытаюсь сделать широковещательное уведомление в Laravel 5.4 и VueJS 2, - PullRequest
0 голосов
/ 07 января 2020

Я пытаюсь сделать широковещательное уведомление при Laravel 5.4 и VueJS 2 поиске много, но решение не работает.

1.config / Broadcasting. php

'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true
],
],
.env
   BROADCAST_DRIVER=pusher
   PUSHER_APP_ID=pusher_app_id
   PUSHER_APP_KEY=pusher_app_key
   PUSHER_APP_SECRET=pusher_app_secret
   PUSHER_APP_CLUSTER=pusher_app_cluster

3. Событие


namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PostPublished implements ShouldBroadcast
{
 use Dispatchable, InteractsWithSockets, SerializesModels;

 /**
  * Create a new event instance.
  *
  * @return void
  */
 public $post;

public function __construct($post) {    
 $this->post = $post;
}

/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn() {
 return new Channel('posts');
}

public function broadcastWith() {

 return [
   'title' => $this->post,
 ];
}
}

4. bootstrap. js


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


5.app . vue


let temp=Echo.channel('posts');      
    temp.listen('PostPublished', post => {
      if (! ('Notification' in window)) {
        alert('Web Notification is not supported');
        return;
      }
      console.log('Pusher Response',post);
    });


6: -ответ при загрузке страницы




Pusher :  : ["State changed","unavailable -> connected with new socket ID 4966.2417633"]
Pusher :  : ["Event sent",{"event":"pusher:subscribe","data":{"channel":"posts"}}]
Pusher :  : ["Event recd",{"event":"pusher_internal:subscription_succeeded","channel":"posts","data":{}}]
Pusher :  : ["No callbacks on posts for pusher:subscription_succeeded"]
Pusher :  : ["Event sent",{"event":"pusher:ping","data":{}}]
Pusher :  : ["Event recd",{"event":"pusher:pong","data":{}}]



необходимо реализовать уведомление с пушером, laravel 5.4, vuejs2, laravel эхо-сервер .но это не работает.

...