@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>
111 lines (107 loc) • 3.18 kB
TypeScript
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}
* Throws an error if:
* - The key is missing or invalid.
* - The value is not a string or exceeds the allowed size (1 KB).
* - The request fails.
*
* @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}
* Throws an error if the key does not exist or the request fails.
*
* @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}
* Throws an error if:
* - The key is invalid or missing.
* - The callback is not a function.
* - The subscription request fails.
*
* @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}
* Throws an error if the observer ID is invalid, not found, or if the
* unsubscribe operation fails.
*
* @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>;
}