Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

WebSockets with pro cli and laravel echo server

chris edited this page Jan 19, 2018 · 1 revision

pro-cli provides the ability to use WebSockets in combination with laravel-echo-server. See the Laravel documentation for further info.

Services you need

  • web
  • redis
  • echo

Initialise laravel-echo-server

By default, Laravel projects (project init test --type=laravel) come with the ./conf/echo/laravel-echo-server.json to allow starting the WebSocket container. You still have to initialise laravel-echo-server by using the appropriate command:

project echo init

Example configuration

{
    "authHost": "http://web",
    "authEndpoint": "/broadcasting/auth",
    "clients": [
        {
            "appId": "APP_ID",
            "key": "APP_KEY"
        }
    ],
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "redis"
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "apiOriginAllow": {
        "allowCors": true,
        "allowOrigin": "http://localhost:80",
        "allowMethods": "GET, POST",
        "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
    }
}

Client configuration (Laravel Echo)

See the Laravel documentation.

Laravel configuration

In your ./src/.env provide the following variables or according to your environment configuration:

BROADCAST_DRIVER=redis

Don't forget to require the redis driver

project composer require predis/predis

Pushing the events

To push the events, you need to run a queue listener.

Debugging / logs

project logs -f echo web

Clone this wiki locally