Max Brown
Max Brown

Reputation: 46

How can I find the information sent from the laravel websocket web server?

I use the websocket server to send the information of an event as a broadcast. But I can not get information through laravel echo . this is my config for laravel and websocket server.

broadcasting config

    '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'),
            // 'encrypted' => true,
            'host' => '127.0.0.1',
            'port' => 6001,
            'scheme' => 'http',
            //disable cros orgin
            'useTLS' => false,
        ],
    ],

websockets config

 '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,
    ],
],

env config

PUSHER_APP_ID=your-pusher-app-id
PUSHER_APP_KEY=your-pusher-key
PUSHER_APP_SECRET=your-pusher-secret
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_PORT=6001

boostrap.js

window.Echo = new Echo({
broadcaster: 'pusher',
key: "your-pusher-key",
cluster: "mt1",
wsHost: window.location.hostname,
wsPort: 6001,

//two config above disable crose orgin
disableStats: true,
forceTLS: false,

});

My event file

class OrderStatusChange implements ShouldBroadcast{ 

use Dispatchable, InteractsWithSockets, SerializesModels;

public $message;
public $user;

public function __construct($message,$user)
{
   $this->message = $message;
   $this->user = $user;
}


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

}

and laravel-echo

 window.Echo.channel('notifications').listen('OrderStatusChange', (e) => {
console.log(e.data);
console.log(e);
console.log('window');

});

and console da

Pusher :  : ["State changed","initialized -> connecting"] app.js:38851:32

Pusher : : ["Connecting",{"transport":"ws","url":"ws://shop.local:6001/app/your-pusher-key?protocol=7&client=js&version=7.0.2&flash=false"}] app.js:38851:32 Pusher : : ["State changed","connecting -> connected with new socket ID 307045135.646205772"] app.js:38851:32 Pusher : : ["Event sent",{"event":"pusher:subscribe","data":{"auth":"","channel":"order"}}] Pusher : : ["Event recd",{"event":"pusher_internal:subscription_succeeded","channel":"order"}] app.js:38851:32 Pusher : : ["No callbacks on order for pusher:subscription_succeeded"]

Upvotes: 0

Views: 1194

Answers (2)

Max Brown
Max Brown

Reputation: 46

Thanks everyone i found solution used wrote the answer maybe help someone Just run the queue and If you do not need queues only in the env file Change the value of QUEUE_CONNECTION to sync And also use the ShouldBroadcastNow value in the event class

Upvotes: 1

Mohammad Aliyari
Mohammad Aliyari

Reputation: 126

do you use broadcastWith function in your event?

in this function, you can define the data that you want to broadcast. besides, make sure that your WebSocket is successfully connected.

Upvotes: 0

Related Questions