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:
hubfly realtime bind chat --to shop --preset laravelElsewhere, print the same variables and add them to your .env:
hubfly realtime env chat --preset laravel --reveal >> .envBROADCAST_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:
'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
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'sencryption_master_key_base64option) and load thepusher-js/with-encryptionbuild in the browser. See end-to-end encryption.
Hubfly space features beyond Pusher
Check that it works
- Open your app in a browser so Echo connects.
- Watch traffic with
hubfly realtime tail chator the server's Debug console; you should see the connection and its subscriptions. - 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.