I'm trying to use laravel websocket to preform socket connection in my app.
Doing all the steps in laravel docs but still not working, no connection appearing in dashborad, only event if I fired from laravel tinker(not fire the console.log I put in listen method)
Attached the files I have for more information about the case.
Server side :
Websocket.php file
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
]
Event file
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class CustomerUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('customers');
}
// public function broadcastAs()
// {
// return "customers-updated";
// }
}
Client side with laravel echo:
Service:
this.echo = new Echo({
broadcaster: 'pusher',
key: environment.pusher.key,
cluster: environment.pusher.cluster,
// wsPort: 6001,
// wsHost: 'http://crm.test/api',
// useTLS: false,
disableStats: true
});
Component:
const channel = this.echoService.echo.channel('customers').listen('CustomerUpdated', (e) => {
console.log(e);
});
api-message Channel: customers, Event: App\Events\CustomerUpdated 22:45:31
subscribed 555985715.292445342 Channel: private-websockets-dashboard-statistics 22:36:49
occupied Channel: private-websockets-dashboard-statistics 22:36:49