cuartas15
1 week ago

Laravel Websockets is not working sometimes

Posted 1 week ago by cuartas15

I'm using the latest version of everything, Laravel Websockets, Laravel, Laravel Echo, Axios and so on and so forth.

I 100% based my Forge configuration on this guide https://alex.bouma.dev/installing-laravel-websockets-on-forge/

One of my clients reported thay they weren't getting any updates at some point for changes on an appointments module, he had to refresh the page to get it working again.

The weird part is that he was still receiving messages from a small chat module my app has that is based on the same principle.

This is a little bit of code: My Vue file:

/**
* Starts listening to update appointments events.
*
*/
updateAppointments() {
    Echo.channel(`update-appointments.${this.office_id}`)
        .listen('.list.new.appointments', (event) => {
            if (!this.isEditingAppointment) {
                this.checkAppointments();
            } else {
                this.pendingUpdateFlag = true;
            }
        })
        .listen('.list.updated.dates', (event) => {
            this.listDates(false);
        })
        .listen('.list.updated.entities', (event) => {
            this.listEntities();
        })
        .listen('.list.updated.locations', (event) => {
            this.listLocations();
            this.listAppointments();
        });
}

Channels.php:

// Appointments events
Broadcast::channel('update-appointments.{officeId}', function ($user, $officeId) {
    return ($user->hasPermission('appointments') && $user->office_id === $officeId);
});

Then the event files you know that I'm not going to include here to simplify this post.

As a side note, I'm forced to subscribe the users to regular channels since private ones won't work when a parameter is included on the channel's name (like this.office_id) it happens with either Laravel Websockets or an old Echo + Socket.io + redis method I was using in the past.

SMALL UPDATE: As I was writing this post, the same client reported that he didn't receive some chat messages, I asked him if maybe the sender typed both messages very quickly or something, maybe the fake pusher server is not fast enough to give updates in really short periods of time? but yeah, Websockets is not being reliable right now.

I hope you can give me a solution to this.

Thanks in advance

Please sign in or create an account to participate in this conversation.