Hubfly spaceDocs
Console

Laravel Broadcasting

Laravel talks to a Hubfly space realtime server through its built-in Pusher broadcaster, and Laravel Echo connects in the browser with pusher-js. You change environment variables, not code. Hubfly space tests Laravel Echo 2 with its Pusher connector: channels and listen, whispers, presence (here, joining, leaving), notifications and encrypted private channels.

Connection variables

If your Laravel app runs on Hubfly space, connect its Cell project with the Laravel / Pusher preset and redeploy:

bash
hubfly realtime bind chat --to shop --preset laravel

Elsewhere, print the same variables and add them to your .env:

bash
hubfly realtime env chat --preset laravel --reveal >> .env
.env
BROADCAST_CONNECTION=pusher
PUSHER_APP_ID=your-app-id
PUSHER_APP_KEY=your-app-key
PUSHER_APP_SECRET=your-app-secret
PUSHER_HOST=chat-1a2b.rt.hubfly.app
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

The cluster value is a placeholder that pusher-js requires; Hubfly space uses the host. Laravel versions before 11 read BROADCAST_DRIVER=pusher instead of BROADCAST_CONNECTION. A connected project writes the VITE_PUSHER_* values literally, because container environments do not expand ${…}.

Broadcasting

Install broadcasting with the Pusher driver if you have not already (php artisan install:broadcasting on Laravel 11 and later). The pusher connection in config/broadcasting.php reads the variables above; make sure its options use the host, port and scheme:

config/broadcasting.php
'pusher' => [
    'driver' => 'pusher',
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'app_id' => env('PUSHER_APP_ID'),
    'options' => [
        'cluster' => env('PUSHER_APP_CLUSTER'),
        'host' => env('PUSHER_HOST'),
        'port' => env('PUSHER_PORT', 443),
        'scheme' => env('PUSHER_SCHEME', 'https'),
        'encrypted' => true,
        'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
    ],
],

Events that implement ShouldBroadcast and notifications on the broadcast channel are then delivered through your Hubfly space server.

Laravel Echo

resources/js/echo.js
import Echo from "laravel-echo";
import Pusher from "pusher-js";

window.Pusher = Pusher;

window.Echo = new Echo({
  broadcaster: "pusher",
  key: import.meta.env.VITE_PUSHER_APP_KEY,
  cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
  wsHost: import.meta.env.VITE_PUSHER_HOST,
  wsPort: import.meta.env.VITE_PUSHER_PORT,
  wssPort: import.meta.env.VITE_PUSHER_PORT,
  forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? "https") === "https",
  enabledTransports: ["ws", "wss"],
});

Rebuild your frontend assets after changing VITE_* variables: Vite reads them at build time.

Private and presence channels

Your Laravel broadcast auth route (/broadcasting/auth) and the rules in routes/channels.php still decide who may join private and presence channels. Hubfly space never calls your app for authorization; it only checks the signature that Laravel returns to the browser.

  • Whispers (Echo.private(…).whisper(…)) are client events: turn on Client events in the app settings.
  • For Echo.encryptedPrivate, set an encryption master key in your Pusher config as with Pusher (Laravel's encryption_master_key_base64 option) and load the pusher-js/with-encryption build in the browser. See end-to-end encryption.

Hubfly space features beyond Pusher

Laravel uses the Pusher protocol, so it gets channels, presence, whispers and user notifications. Session resume, direct messages to a connection, delivery receipts and full end-to-end encryption need the Hubfly space client.

Check that it works

  1. Open your app in a browser so Echo connects.
  2. Watch traffic with hubfly realtime tail chat or the server's Debug console; you should see the connection and its subscriptions.
  3. Dispatch a broadcast event from Laravel (for example in php artisan tinker) and check that the browser receives it.

If the browser never connects, check that VITE_PUSHER_HOST is your Hubfly space host and the assets were rebuilt. If private channels fail with 403, check your routes/channels.php rules. More in Debug and monitor.

Something unclear or out of date? Emailsupport@hubfly.spaceBack to top