Я использую пакет Laravel Websockets. На стороне сервера все выглядит отлично, но Laravel Echo не прослушивает события .. MySocketEvent. php:
<?php
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 MySocketEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($data)
{
//
$this->data=$data;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('DemoChannel.1');
}
public function broadcastAs()
{
return 'testing';
}
}
Интернет. php
Route::get('tests',function(){
$arr=['some'=>'some'];
broadcast(new \App\Events\MySocketEvent($arr));
return view('hi');
});
Bootstrap. js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
//key: process.env.MIX_PUSHER_APP_KEY,
key: 'my-key',
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
disableStats: true,
cluster: 'ap2',
//cluster: process.env.MIX_PUSHER_APP_CLUSTER,
//encrypted: true
});
//subscribe-for-the-test-demo-channel-and-listen
window.Echo.channel('DemoChannel.1')
.listen('.testing', (e) => {
console.log("Received Data: ");
console.log(e);
});
Я вижу данные, отправленные с сервера используя php artisan WebSockets: обслуживайте, но Laravel Echo не слушает. Пожалуйста помоги. Я на 100% уверен, что проблема в Laravel Echo.