Laravel laravel-echo-server not receiving messages (chat)

by Jenssen   Last Updated September 11, 2019 17:26 PM

I'm trying to setup laravel-echo-server but I can't get it to work. With the same setup (I use Vue.js) it's working with pusher. I have build a chat.

My laravel-echo-server.json looks like this:

{
    "authHost": "https://sayhidog.test",
    "authEndpoint": "/broadcasting/auth",
    "clients": [],
    "database": "redis",
    "databaseConfig": {
        "redis": {},
        "sqlite": {}
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "https",
    "socketio": {},
    "secureOptions": 67108864,
    "sslCertPath": "/Users/lars/.config/valet/Certificates/sayhidog.test.crt",
    "sslKeyPath": "/Users/lars/.config/valet/Certificates/sayhidog.test.key",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": false,
        "allowOrigin": "",
        "allowMethods": "",
        "allowHeaders": ""
    }
}

When I run laravel-echo-server start I see:

enter image description here

This looks great, when I send a message I see:

enter image description here

In vue.js I connect like this:

window.io = require('socket.io-client');

    if (typeof io !== 'undefined') {
        window.Echo = new Echo({
            broadcaster: 'socket.io',
            host: window.location.hostname + ':6001',
        });
    }

And I listen like this:

window.Echo.private('chat')
    .listen('MessageSent', (e) => {
        this.messages.push({
            body: e.message.body,
            user: e.user
        });
    });

My channels.php looks like this:

Broadcast::channel('chat', function ($user) {
    return true;
});

In my Controller I broadcast:

broadcast(new MessageSent($user, $message))->toOthers();

The MessageSent looks like this:

class MessageSent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
/**
 * User that sent the message
 *
 * @var User
 */
public $user;

/**
 * Message details
 *
 * @var ChatMessage
 */
public $message;

/**
 * Create a new event instance.
 *
 * @param User $user
 * @param ChatMessage $message
 */
public function __construct(User $user, ChatMessage $message)
{
    $this->user = $user;
    $this->message = $message;
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('chat');
}

}

The connection in my network tab looks fine:

enter image description here

I don't get any new messages in my chat. With pusher it's working. What could I be doing wrong here? Thanks!



Related Questions


Updated July 19, 2017 01:26 AM

Updated February 26, 2019 05:26 AM

Updated July 30, 2017 13:26 PM

Updated November 12, 2018 14:26 PM

Updated August 27, 2017 09:26 AM