Skip to content

Commit e9f8342

Browse files
committed
[RealtimeKit] Document store APIs for mobile platforms
1 parent 9ff5648 commit e9f8342

File tree

1 file changed

+114
-5
lines changed
  • src/content/docs/realtime/realtimekit/collaborative-stores

1 file changed

+114
-5
lines changed

src/content/docs/realtime/realtimekit/collaborative-stores/index.mdx

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import RTKCodeSnippet from "~/components/realtimekit/RTKCodeSnippet/RTKCodeSnipp
1111

1212
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.
1313

14-
<RTKSDKSelector />
14+
<RTKSDKSelector disabledPlatforms={["mobile-flutter"]} />
1515

1616
### Create a Store
1717

@@ -23,7 +23,7 @@ You can create a realtime store (changes are synced with other users):
2323

2424
To create a store:
2525

26-
<RTKCodeSnippet id="web-react">
26+
<RTKCodeSnippet id={["web-react", "mobile-react-native"]}>
2727

2828
```ts
2929
const stores = useRealtimeKitSelector((m) => m.stores);
@@ -44,6 +44,30 @@ const store = meeting.stores.create('myStore');
4444
````
4545
</RTKCodeSnippet>
4646

47+
<RTKCodeSnippet id="mobile-android">
48+
49+
```kotlin
50+
val meeting = RealtimeKitMeetingBuilder.build(activity)
51+
val store = meeting.stores.create("myStore")
52+
```
53+
54+
</RTKCodeSnippet>
55+
56+
<RTKCodeSnippet id="mobile-ios">
57+
58+
```swift
59+
let meeting = RealtimeKitiOSClientBuilder().build()
60+
let store = meeting.stores.create(name: "myStore")
61+
```
62+
63+
</RTKCodeSnippet>
64+
65+
<RTKCodeSnippet id="mobile-flutter">
66+
67+
This feature is not currently supported in the Flutter SDK
68+
69+
</RTKCodeSnippet>
70+
4771
:::note
4872
This method must be executed for every user.
4973
:::
@@ -57,7 +81,7 @@ You can add, update or delete entires in a store:
5781
| `key` | string | Unique identifier used to store/update a value in the store | Yes |
5882
| `value` | StoreValue | Value that can be stored agains a key | Yes |
5983

60-
<RTKCodeSnippet id="web-react">
84+
<RTKCodeSnippet id={"web-react", "mobile-react-native"}>
6185

6286
```ts
6387
type StoreValue = string | number | object | array;
@@ -112,6 +136,25 @@ await store.delete("user");
112136

113137
</RTKCodeSnippet>
114138

139+
<RTKCodeSnippet id="mobile-android">
140+
141+
```kotlin
142+
val store = meeting.stores.get("myStore")
143+
144+
store.set("user", mapOf("name" to "John Doe"))
145+
```
146+
147+
</RTKCodeSnippet>
148+
149+
<RTKCodeSnippet id="mobile-ios">
150+
151+
```swift
152+
let store = meeting.stores.get(name: "myStore")
153+
store.set("user", ["name": "John Doe"])
154+
```
155+
156+
</RTKCodeSnippet>
157+
115158
:::note
116159
The `set` method overwrites the existing value, while the `update` method updates the existing value.
117160

@@ -122,7 +165,7 @@ For example, if the stored value is `['a', 'b']` and you call `update` with `['c
122165

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

125-
<RTKCodeSnippet id="web-react">
168+
<RTKCodeSnippet id={"web-react", "mobile-react-native"}>
126169

127170
```ts
128171
const stores = useRealtimeKitSelector((m) => m.stores.stores);
@@ -180,11 +223,49 @@ store.unsubscribe('key');
180223

181224
</RTKCodeSnippet>
182225

226+
<RTKCodeSnippet id="mobile-android">
227+
228+
```kotlin
229+
val store = meeting.stores.create("myStore")
230+
val keyChangeCallback = { key: String, value: Any? ->
231+
println(value)
232+
}
233+
store.subscribe("key", keyChangeCallback)
234+
235+
// Subscribe to all keys
236+
store.subscribe(RtkStore.WILDCARD_KEY) { key, value ->
237+
println(value)
238+
}
239+
240+
store.unsubscribe("key", keyChangeCallback)
241+
```
242+
243+
</RTKCodeSnippet>
244+
245+
<RTKCodeSnippet id="mobile-ios">
246+
247+
```swift
248+
let store = meeting.stores.create(name: "myStore")
249+
let keyChangeCallback: ((String, (Any?)) -> Void) = { key, value in
250+
print(value ?? "null")
251+
}
252+
store.subscribe(key: "key", onChange: keyChangeCallback)
253+
254+
// Subscribe to all keys
255+
store.subscribe(key: RtkStore.Companion().WILDCARD_KEY) { key, value in
256+
print(value ?? "null")
257+
}
258+
259+
store.unsubscribe(key: "key", onChange: keyChangeCallback)
260+
```
261+
262+
</RTKCodeSnippet>
263+
183264
### Fetch Store Data
184265

185266
You can fetch the data stored in the store:
186267

187-
<RTKCodeSnippet id="web-react">
268+
<RTKCodeSnippet id={["web-react", "mobile-react-native"]}>
188269

189270
```ts
190271
const stores = useRealtimeKitSelector((m) => m.stores.stores);
@@ -230,3 +311,31 @@ const data = store.getAll();
230311
````
231312

232313
</RTKCodeSnippet>
314+
315+
<RTKCodeSnippet id="mobile-android">
316+
317+
```kotlin
318+
val store = meeting.stores.create("myStore")
319+
320+
// fetch value for a specific key
321+
val data = store.get("key")
322+
323+
// fetch all the data in the store
324+
val data = store.getAll()
325+
```
326+
327+
</RTKCodeSnippet>
328+
329+
<RTKCodeSnippet id="mobile-ios">
330+
331+
```swift
332+
let store = meeting.stores.create(name: "myStore")
333+
334+
// fetch value for a specific key
335+
store.get(key: "key")
336+
337+
// fetch all the data in the store
338+
store.getAll()
339+
```
340+
341+
</RTKCodeSnippet>

0 commit comments

Comments
 (0)