UNPKG

@videosdk.live/js-sdk

Version:

<h1 align="center"> <img src="https://cdn.videosdk.live/docs/images/javascript/api_ref/js_api_ref.png"/><br/> </h1>

113 lines (109 loc) 3.45 kB
export class realtimeStore { /** * - This method can be used to store or update a value in the Realtime Store. * * - If the specified key already exists, its value is overwritten. Passing `null` as the value deletes the key from the store. * * @param key * A unique identifier used to store the value. * * @param value * The value to store. Pass `null` to delete the key. * * @throws * - **Error** — `key` is missing * - **Error** — `key` is not a string, or `value` is neither a string nor `null` * - {@link Errors.ERROR_PAYLOAD_TOO_LARGE} — value payload exceeds the allowed size (1 KB) * - **Error** — the set request fails on the server * * @example * ```ts * try { * await meeting.realtimeStore.setValue("Blocked_Students", "[Halima, Rajan]"); * console.log("Data set successfully!"); * } catch (error) { * console.error("Failed to set data:", error); * } * ``` */ setValue(key: string, value: string | null): Promise<void>; /** * - This method can be used to retrieve the value associated with a given key. * * @param key * The key whose value should be retrieved. * * @returns * A promise that resolves to the stored value. * * @throws * - **Error** — `key` is missing * - **Error** — `key` is not a string * - **Error** — the get request fails on the server * * @example * ```ts * try { * const value = await meeting.realtimeStore.getValue("Blocked_Students"); * console.log("Current value:", value); * } catch (error) { * console.error("Failed to get data:", error); * } * ``` */ getValue(key: string): Promise<string | null>; /** * - This method can be used to subscribe to real-time updates for a specific key. * * - The provided callback function is executed whenever the value associated with the key is updated by any participant. * * @param key * The key to observe for updates. * * @param callback * A function that handles value updates along with the ID of the participant * who made the change. * * @throws * - **Error** — `key` is missing * - **Error** — `key` is not a string * - **Error** — `callback` is not a function * - **Error** — the underlying subscribe request fails on the server * * @example * ```ts * try { * const observerId = await meeting.realtimeStore.observe( * "Blocked_Students", * (value, updatedBy) => { * console.log("Value updated:", value, "by", updatedBy); * } * ); * } catch (error) { * console.error("Failed to observe key:", error); * } * ``` */ observe(key: string, callback: Function): Promise<string>; /** * - This method can be used to stop receiving updates for a previously registered observer. * * @param observerId * The unique observer ID returned by the `observe()` method. * * @throws * - **Error** — `observerId` is missing or was never returned by `observe()` * - **Error** — the underlying unsubscribe request fails on the server * * @example * ```ts * try { * await meeting.realtimeStore.stopObserving(observerId); * console.log("Stopped observing successfully!"); * } catch (error) { * console.error("Failed to stop observing:", error); * } * ``` */ stopObserving(observerId: string): Promise<void>; }