Channels with permissions
Your function gives each browser a signed token naming the channels it may join and publish to, with wildcards like room-*.
Push updates to every open browser the moment something happens: chat messages, order status, live scores, cursors, notifications. Channels, presence and permissions are built in, the client reconnects by itself, and you pay for messages and connected time with nothing idle to run.
// lyrcloud.json: "realtime": "REALTIME"
export default {
async fetch(request, env) {
const url = new URL(request.url);
// The browser asks for a token after your own sign-in
if (url.pathname === '/realtime-token') {
return Response.json(await env.REALTIME.token({
user: 'ana', channels: ['room-*'], publish: true, presence: true,
}));
}
// Something happened: tell everyone in the room
await env.REALTIME.publish('room-1', { text: 'Order #42 shipped' });
return new Response('ok');
},
};
// <script src="https://www.lyrcloud.com/realtime.js"></script>
// const rt = new LyrRealtime({ auth: () => fetch('/realtime-token').then((r) => r.json()) });
// rt.subscribe('room-1', (data, msg) => console.log(msg.from, data));
Your function gives each browser a signed token naming the channels it may join and publish to, with wildcards like room-*.
env.REALTIME.publish() in a function, rt.publish() in the browser, the API, or lyrcloud realtime publish.
See who is in a channel, and get join and leave events with each userβs name or avatar.
One script tag or lyrcloud/realtime. It reconnects with a fresh token, rejoins its channels and keeps the connection alive.
Thousands of connections on managed WebSockets, with no sockets server to size, patch or keep warm.
Launch: 100 connections, 500,000 messages a month. Scale: 5,000 and 10M. Enterprise: 50,000 and 100M. Past that, $1.50 per million messages from Lyrcloud credit.
Register or transfer a domain with free WHOIS privacy and Lyrcloud DNS, paid by card or with Lyrpay.
Learn moreResponse caching, static files and whole static sites for your edge functions, with cache headers you control and purges from the CLI.
Learn moreRate limits, IP rules, a firewall for common attacks, bot checks and secure headers for your edge functions, set in lyrcloud.json and enforced before your code runs.
Learn moreCreate a free account in under a minute. No credit card required.