vendredi 14 octobre 2016

Broadcasting with Laravel Echo, laravel-echo-server and socket.io won't work

I've setup websockets with Laravel sucessfully with an own implementation. Now I'd like to switch to Laravel Echo and laravel-echo-server. But, after many hours of trying and reading every piece of documentation I could find, I do need further help.

What's happening when I fire an event: The queue worker processes the event as desired: "Processed: Illuminate\Broadcasting\BroadcastEvent". But nothing happens in the laravel-echo-server console nor on the client.

Some information:

  • Laravel is running on port 8001

  • Redis is running on 6379

  • the queue worker is running (php artisan queue:work)

  • Laravel, Redis and laravel-echo-server are running on the same machine (192.168.134.214)

  • when trying private channels the authentication in the BroadcastServiceProvider seems to work (the server writes errors to the console if it fails)

  • the client uses the socket.io script of the laravel-echo-server: <script src="//192.168.134.214:6001/http://ift.tt/1aeIZU4"></script>

Excerpt of my .env:

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

The laravel-echo-server.json:

{
    "appKey": "<myAppKey>",
    "authEndpoint": "/broadcasting/auth",
    "authHost": "http://localhost:8001",
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "http://localhost"
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": "192.168.134.214",
    "port": "6001",
    "sslCertPath": "",
    "sslKeyPath": ""
}

app.js

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://ift.tt/2dTkLi6',
});

app.blade.php

<script>
    Echo.channel('mychan')
        .listen('myevent', (e) => {
            console.log('Hello World!', e);
        });
</script>

Parts of the Event "NewsPublished":

class NewsPublished implements ShouldBroadcast {
    use InteractsWithSockets, SerializesModels;

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

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

..and I'm firing the Event with event(new App\Events\NewsPublished());

I was hoping to get some information out of the laravel-echo-server when switching "devMode" to true. But that doesn't seem to change anything!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire