0

I'm having trouble receiving WebSocket messages in Postman when using Laravel 10 and the beyondcode/laravel-websockets package. I've followed the steps below, but I'm still not receiving the broadcasted messages in Postman.

Steps taken:

  1. Installed the beyondcode/laravel-websockets package and configured it according to the documentation.
  2. Created a TestEvent class that implements the ShouldBroadcast interface and returns the correct channel name.
  3. Defined the channel in the routes/channels.php file.
  4. Broadcasted the TestEvent from a controller or route.
  5. In Postman, established a WebSocket connection with the correct URL (ws://localhost:6001/app/my-app-id).
  6. Subscribed to the correct channel by sending the pusher:subscribe event with the channel name.

Despite following these steps, I'm not receiving the broadcasted TestEvent message in Postman. I've checked the logs, and there are no errors or exceptions related to the WebSocket server or broadcasting the event.

Here's the relevant code:

routes/channels.php

Broadcast::channel('test_message', function () {
    return true;
});

events/TestEvent.php

<?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 TestEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

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

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

    public function broadcastAs()
    {
        return 'testEvent';
    }
}

Broadcasting the event routes/web.php

Route::get('/', function () {
    event(new testEvent("It works!"));
    return "hello there";
});

I've also tried using different channels and event names, but the issue persists. I'm not sure what else to check or what I might be missing. Any help or guidance would be greatly appreciated.

postman window

0

Browse other questions tagged or ask your own question.