Documentation menu

Chat: live updates (Reverb) or polling

Customers and providers chat in conversations:

  • one per booking, opened when the booking is created;
  • one per job request and provider, opened when the provider sends a quote.

Messages, photos, read ticks, typing, block and report all work in both modes below. The only difference is how fast the other side sees things.

Mode When Speed
Live (Laravel Reverb websockets) A VPS or any server that can run a long-lived process Instant, with a typing indicator
Polling Shared hosting, or Reverb is off or down The open chat checks every 5 s and the chat list every 30 s. No typing indicator

The app chooses the mode from GET /api/v1/config → realtime. If enabled is false, it polls. You don't need a new app build to switch modes.

Polling (default, works everywhere)

Set this in backend/.env:

BROADCAST_CONNECTION=log

That's all. Nothing else needs to run.

Live chat with Reverb (VPS)

1. Set the keys in backend/.env

BROADCAST_CONNECTION=reverb

REVERB_APP_ID=niceserve
REVERB_APP_KEY=<random 20 chars>
REVERB_APP_SECRET=<random 20 chars>

# Where Laravel itself reaches Reverb (same machine):
REVERB_HOST=127.0.0.1
REVERB_PORT=8080
REVERB_SCHEME=http

# What the app connects to (sent in GET config):
REVERB_PUBLIC_HOST=ws.example.com
REVERB_PUBLIC_PORT=443
REVERB_PUBLIC_SCHEME=https

Then run php artisan config:cache.

2. Keep Reverb running

Here is a Supervisor example, /etc/supervisor/conf.d/reverb.conf:

[program:reverb]
command=php /var/www/niceserve/backend/artisan reverb:start --host=127.0.0.1 --port=8080
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/reverb.log
minfds=10000

After a deploy, run php artisan reverb:restart.

3. Proxy websockets through Nginx with TLS

server {
    listen 443 ssl;
    server_name ws.example.com;
    # ssl_certificate … (e.g. from certbot)

    location / {
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080;
    }
}

4. Check it

GET /api/v1/config should return:

"realtime": {"enabled": true, "key": "…", "host": "ws.example.com", "port": 443, "scheme": "https",
             "auth_endpoint": "https://api.example.com/api/v1/broadcasting/auth"}

Open a chat in the app on two phones. Messages and "typing…" should show up instantly.

How it works

  • Channel: private-conversation.{id}. Only the two participants can join it. The app authorizes at auth_endpoint with its API token (Sanctum).
  • Events: message.sent (the full message), message.read (user_id, last_read_message_id) and typing (user_id). They're sent right away, with no queue.
  • Sending: sending always goes through the API: POST conversations/{id}/messages with a client_id. A retry with the same client_id never creates a duplicate.
  • Missed messages: after a reconnect, or in polling mode, the app asks for anything newer: GET conversations/{id}/messages?after_id=….
  • Push: a new message sends a push notification unless the recipient has that chat open. The app tells the server every 45 s while a chat is open.
  • Contact masking: with the chat.mask_contacts setting on, emails and phone numbers (8+ digits) are hidden, so people can't take the deal off the platform.
  • Moderation: users can block each other, and reports show up in the admin panel under Chat reports.

Local development

Here's the setup on an Android emulator:

REVERB_PUBLIC_HOST=10.0.2.2
REVERB_PUBLIC_PORT=8080
REVERB_PUBLIC_SCHEME=http

Then run php artisan reverb:start --host=0.0.0.0 --port=8080 --debug. The auth endpoint follows the host the app called, so 10.0.2.2:8000 works without changes.