Realtime between two users. No socket server to run.
A chat or a notification feed sounds small. Then you run a socket server and Redis, wire your login into them, keep both online, and add AJAX calls to get anything back to your server.
RealtimeHub is that server. Your backend asks for a token. Your frontend connects with it and sends to another user, on one connection that works both ways. Every message can also reach your Laravel app through a webhook, with no command to keep running, and your backend can message any user with one call.
What you get.
Tokens from your backend
Your secret stays on your server. It asks the hub for a short-lived token for the signed-in user, and the browser connects with that. Users can only appear as who your login says they are.
A schema for each event
Describe a payload with JSON Schema and the hub checks every message before it reaches anyone. The sender gets the field and the reason back. Strict mode refuses events you have not described.
Messages in your Laravel app
Live delivery forgets. Turn on the webhook and the hub sends each message to a route in your app, signed and in order. Failures are retried, and a repeated message is never saved twice. Nothing to keep running.
Three calls. This is the whole surface.
Route::get('/hub-token', function () {
$hub = config('hub');
return Http::withToken($hub['secret'])
->post($hub['url'].'/api/token', [
'appKey' => $hub['key'],
'userId' => (string) auth()->id(),
])->throw()->json();
})->middleware('auth');Your backend asks the hub for a token for the signed-in user.
import { createRealtimeClient }
from '/sdk/realtimehub-client.js';
const client = createRealtimeClient({
hubUrl: 'https://hub.example.com/hub/chat',
fetchToken: () =>
fetch('/hub-token').then(r => r.json()),
onEvent: (m) => console.log(m),
});
await client.start();
await client.send('bob', 'chat', { text: 'hi' });The browser connects with that token and sends to one user.
{
"type": "object",
"required": ["text"],
"properties": {
"text": {
"type": "string",
"maxLength": 500
}
},
"additionalProperties": false
}A message that does not match is rejected, with the reason.
Limits.
Start with one app.
Create an app
Sign up, confirm your email, and make an app in the dashboard. You get a key and a secret.
Add the token route
Paste the backend snippet with your values already filled in. It is the first code block above.
Connect and send
Load the browser client, connect with the token, and call send. The docs have every option.
Create an account.
Three apps per account. The dashboard shows each app's key and secret, and the snippets above with your values filled in.