Realtime between two users. No socket server to run.
A chat or a notification feed sounds small. Then you run a WebSocket server, wire your login into it, keep it online, and write the code that saves what passed through.
RealtimeHub is that server. Your backend asks for a token. Your frontend connects with it and sends to another user. Every message can also land in your own database through a Laravel command.
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 database
Live delivery forgets. Turn on persistence and each message also goes to a Redis stream for your app. A Laravel command saves it in your own database, retries failures, and never writes the same message twice.
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.