مجید
5 سال پیش توسط مجید مطرح شد
0 پاسخ

مشکل در دریافت اطلاعات در وب سوکت و ایونت لاراول

سلام من می خواهم یک ایونت رو اجرا می کنم اما اطلاعاتی از سمت سرور و یا لاراول اکو دریافت نمیشود
تنظیمات وب سوکت

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

تنظیمات برود کست


        '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',
                'useTLS' => false,
            ],
        ],

تنظیمات bootstrap.js

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: "your-pusher-key",
    cluster: "mt1",
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    forceTLS: false,
});

فایل ایونت

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('order');
    }
}

این کد هم داخل مستر برای دریافت اطلاعات گذاشتم

 Echo.channel('order').listen('OrderStatusChange', (e) => {
                        console.log(e);
        });

و با یک روت ایونت رو صدا می زنم اما هیچ اطلاعات در یافت نمی کنم

 Route::get('/test',function(){

        $message='productdata';
        $user='username';
        event(new App\Events\OrderStatusChange('productdata','$userid'));
        return "ok";

 });

اطلاعات کنسول

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"]