Skip to content

Commit 3f082c3

Browse files
ishita1805Oxyjunswapnilmadavi
authored
feat: add docs for realtime stores (#26983)
* feat: add docs for realtime stores * fix: remove local store docs * fix: ci checks [skip style guide checks] * fix: slugs * fix: add redirects for changed slugs * fix: ci checks [skip style guide checks] * PCX review * Apply suggestions from code review * Update src/content/docs/realtime/realtimekit/collaborative-stores/index.mdx Co-authored-by: Swapnil Madavi <[email protected]> * Update src/content/docs/realtime/realtimekit/collaborative-stores/index.mdx Co-authored-by: Swapnil Madavi <[email protected]> * Update src/content/docs/realtime/realtimekit/collaborative-stores/index.mdx Co-authored-by: Swapnil Madavi <[email protected]> * Update src/content/docs/realtime/realtimekit/collaborative-stores/index.mdx Co-authored-by: Swapnil Madavi <[email protected]> * Apply suggestion from @swapnilmadavi Co-authored-by: Swapnil Madavi <[email protected]> * Apply suggestion from @swapnilmadavi Co-authored-by: Swapnil Madavi <[email protected]> * fix: store api methods [skip style guide checks] * fix: remove api for populating stores [skip style guide checks] * fix: remove duplicate note [skip style guide checks] --------- Co-authored-by: Jun Lee <[email protected]> Co-authored-by: Swapnil Madavi <[email protected]>
1 parent e39f4b5 commit 3f082c3

File tree

8 files changed

+108
-19
lines changed

8 files changed

+108
-19
lines changed

public/__redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
/realtime/pricing/ /realtime/sfu/pricing/ 302
339339
/realtime/changelog/ /realtime/sfu/changelog/ 302
340340
/realtime/realtimekit/get-started/ /realtime/realtimekit/quickstart/ 302
341+
/realtime/realtimekit/core/breakout-rooms/ /realtime/realtimekit/ui-kit/breakout-rooms/ 302
341342
/realtime/realtimekit/getting-started/ /realtime/realtimekit/quickstart/ 302
342343
/realtime/introduction/ /realtime/realtimekit/introduction/ 302
343344
/realtime/concepts/ /realtime/realtimekit/concepts/ 302
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
pcx_content_type: navigation
3+
title: Storage and Broadcast
4+
sidebar:
5+
label: Collaborative Stores
6+
order: 7
7+
---
8+
9+
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](/realtime/realtimekit/concepts/meeting/#session) is active.
10+
11+
### Create a Store
12+
13+
You can create a realtime store (changes are synced with other users):
14+
15+
| Param | Type | Description | Required |
16+
| --------- | --- | --- | --- |
17+
| `name` | string | Name of the store | true |
18+
19+
To create a store:
20+
21+
```ts
22+
const store = meeting.stores.create('myStore');
23+
```
24+
25+
:::note
26+
This method must be executed for every user.
27+
:::
28+
29+
### Update a Store
30+
31+
You can add, update or delete entires in a store:
32+
33+
| Param | Type | Description | Required |
34+
| ----- | ---------- | ----------------------------------------------------------- | -------- |
35+
| `key` | string | Unique identifier used to store/update a value in the store | Yes |
36+
| `value` | StoreValue | Value that can be stored agains a key | Yes |
37+
38+
39+
```ts
40+
type StoreValue = string | number | object | array;
41+
```
42+
```ts
43+
const { stores } = meeting.stores;
44+
const store = stores.get('myStore');
45+
46+
await store.set('user', { name: 'John Doe' });
47+
48+
await store.update('user', { age: 34 }); // { name: 'John Doe', age: 34 }
49+
50+
await store.delete('user');
51+
```
52+
53+
:::note
54+
The `set` method overwrites the existing value, while the `update` method updates the existing value.
55+
56+
For example, if the stored value is `['a', 'b']` and you call `update` with `['c']`, the final value will be `['a', 'b', 'c']`.
57+
:::
58+
59+
60+
### Subscribe to a Store
61+
62+
You can attach event listeners on a store's key, which fire when the value changes.
63+
64+
```ts
65+
const { stores } = meeting.stores;
66+
const store = stores.get('myStore');
67+
store.subscribe('key', (data) => {
68+
console.log(data);
69+
});
70+
71+
// subscribe to all keys of a store
72+
store.subscribe('*', (data) => {
73+
console.log(data);
74+
});
75+
76+
store.unsubscribe('key');
77+
```
78+
79+
### Fetch Store Data
80+
81+
You can fetch the data stored in the store:
82+
```ts
83+
const { stores } = meeting.stores;
84+
const store = stores.get('myStore');
85+
86+
// fetch value for a specific key
87+
const data = store.get('key');
88+
89+
// fetch all the data in the store
90+
const data = store.getAll();
91+
```

src/content/docs/realtime/realtimekit/faq.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: FAQ
44
slug: realtime/realtimekit/faq
55
sidebar:
6-
order: 8
6+
order: 9
77
---
88
import { Details } from "~/components";
99

src/content/docs/realtime/realtimekit/legal/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: Legal
44
hideChildren: true
55
sidebar:
6-
order: 9
6+
order: 10
77

88
---
99

src/content/docs/realtime/realtimekit/quickstart.mdx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,18 @@ Select a framework based on the platform you are building for.
3636
<RTKSDKSelector />
3737

3838
<RTKCodeSnippet id="web-react">
39-
40-
Please install the following dependencies into your project repository:
41-
42-
```bash
43-
npm i @cloudflare/realtimekit-react @cloudflare/realtimekit-react-ui
44-
```
45-
46-
_Optional:_ You can also build on top of our ready-made template:
47-
48-
```bash
49-
git clone https://github.com/cloudflare/realtimekit-web-examples.git
50-
cd realtimekit-web-examples/react-examples/examples/default-meeting-ui
51-
```
52-
39+
Please install the following dependancies into your project repository:
40+
41+
```bash
42+
npm i @cloudflare/realtimekit-react @cloudflare/realtimekit-react-ui
43+
```
44+
45+
_Optional:_ You can also build on top of our ready-made template:
46+
47+
```bash
48+
git clone https://github.com/cloudflare/realtimekit-web-examples.git cd
49+
realtimekit-web-examples/react-examples/examples/default-meeting-ui
50+
```
5351
</RTKCodeSnippet>
5452

5553
<RTKCodeSnippet id="web-web-components">

src/content/docs/realtime/realtimekit/recording-guide/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: navigation
33
title: Recording
44
sidebar:
5-
order: 7
5+
order: 8
66
label: Overview
77
---
88

src/content/docs/realtime/realtimekit/rest-api-reference.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: REST API Reference
44
slug: realtime/realtimekit/rest-api-reference
55
external_link: /api/resources/realtime_kit/
66
sidebar:
7-
order: 8
7+
order: 11
88
badge:
99
text: API
1010
variant: note

src/content/docs/realtime/realtimekit/ui-kit/breakout-rooms.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: navigation
33
title: Breakout Rooms
4-
slug: realtime/realtimekit/core/breakout-rooms
54
sidebar:
65
order: 8
76
---

0 commit comments

Comments
 (0)