Skip to content
Cloudflare Docs

Storage and Broadcast

The RealtimeKit Stores API allows you to create multiple key-value pair realtime stores. Users can subscribe to changes in a store and receive real-time updates. Data is stored until a session is active.

Create a Store

You can create a realtime store (changes are synced with other users):

ParamTypeDescriptionRequired
namestringName of the storetrue

To create a store:

TypeScript
const store = meeting.stores.create('myStore');

Update a Store

You can add, update or delete entires in a store:

ParamTypeDescriptionRequired
keystringUnique identifier used to store/update a value in the storeYes
valueStoreValueValue that can be stored agains a keyYes
TypeScript
type StoreValue = string | number | object | array;
TypeScript
const { stores } = meeting.stores;
const store = stores.get('myStore');
await store.set('user', { name: 'John Doe' });
await store.update('user', { age: 34 }); // { name: 'John Doe', age: 34 }
await store.delete('user');

Subscribe to a Store

You can attach event listeners on a store's key, which fire when the value changes.

TypeScript
const { stores } = meeting.stores;
const store = stores.get('myStore');
store.subscribe('key', (data) => {
console.log(data);
});
// subscribe to all keys of a store
store.subscribe('*', (data) => {
console.log(data);
});
store.unsubscribe('key');

Fetch Store Data

You can fetch the data stored in the store:

TypeScript
const { stores } = meeting.stores;
const store = stores.get('myStore');
// fetch value for a specific key
const data = store.get('key');
// fetch all the data in the store
const data = store.getAll();