Realtime messaging for Laravel, React and mobile apps

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.

LaravelReactReact Nativeplain JavaScript
app: acme-chat / event: chat
Aalice
Is the build green?delivered
Yes. Deploying now.
{ "text": 42 }refused: /text: Value is "integer" but should be "string"
Bbob
Is the build green?
Yes. Deploying now.delivered
schema chat checked on every message

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.

(03)
routes/web.php
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');
POST /api/tokenYour backend

Your backend asks the hub for a token for the signed-in user.

app.js
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' });
send(user, event, data)Your frontend

The browser connects with that token and sends to one user.

schema: chat
{
  "type": "object",
  "required": ["text"],
  "properties": {
    "text": {
      "type": "string",
      "maxLength": 500
    }
  },
  "additionalProperties": false
}
SchemaPer event

A message that does not match is rejected, with the reason.

Limits.

(05)
3AppsEach account can create three apps, each with its own key, secret and allowed origins.
100/ secondMessage ratePer app, with a burst of 200. One connection can send 10 a second, with a burst of 20.
1,000ConnectionsEach app can hold 1,000 open connections at the same time.
32 KBPayloadA message payload is JSON of up to 32 KB.
50SchemasEach app can describe up to 50 events, each with a schema of up to 64 KB.

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.