Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel echo not receiving broadcast

I am trying to receive a broadcast event through via Laravel Echo using Vue 2 and laravel-echo-server, but it just won't work. I have put laravel-echo-server into dev mode as well, and can see that I enter the channel, but then leave at the same time? If that is the problem, how do I stop that from happening and stay in the channel? I can also see that the broadcast is being fired because I'm running php artisan queue:work redis and every time I send the event request I get Processed: Illuminate\Broadcasting\BroadcastEvent, so I know that's working as well. Why won't this work? I'm literally going mad.

Here is my bootstrap.js:

window._ = require('lodash');

window.$ = window.jQuery = require('jquery');
require('bootstrap-sass');

window.Vue = require('vue');
require('vue-resource');

Vue.http.interceptors.push((request, next) => {
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);

    next();
});

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://test.dev:6001'
});

my app.js:

require('./bootstrap');

Vue.component('alert', require('./components/Alert.vue'));

const app = new Vue({
    el: '#app',
    data: {
        users: []
    },
    created: function () {
        window.Echo.channel('test-channel')
            .listen('UserSignedUp', (e) => {
                console.log(e);
                console.log('test');
            });
    }
});

My event:

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class UserSignedUp implements ShouldBroadcast
{
    use InteractsWithSockets, SerializesModels;

    public $username;

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

    public function broadcastOn()
    {
        return new Channel('test-channel');
    }
}

and lastly, my laravel-echo-server.json:

{
    "appKey": "somekey",
    "authHost": "http://test.dev",
    "authEndpoint": "/broadcasting/auth",
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "localhost"
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": "localhost",
    "port": "6001",
    "referrers": [],
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": ""
}

I do not get any errors, anywhere, and it appears that my event is being fired and processed, but Echo just isn't receiving the event. As previously mentioned, each time the event is fired, I get this from the console (laravel-echo-server terminal tab):

[TIME] - KEY joined channel: test-channel
[TIME] - KEY left channel: test-channel
like image 928
A. Appleby Avatar asked Dec 01 '25 09:12

A. Appleby


1 Answers

Yeah for some reason my BROADCAST_DRIVER in my .env file was set to log. Clever me (y)

like image 166
A. Appleby Avatar answered Dec 04 '25 00:12

A. Appleby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!