/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Microsoft Live Share SDK License. */ import { UserMeetingRole, LivePresenceData } from "@microsoft/live-share"; import { IUseLivePresenceResults } from "../types/index.js"; /** * React hook for using a Live Share `LivePresence`. * * @remarks * Use this hook if you want to track presence for who is currently using this component, such as * who is online or who is viewing a specific document. With presence, you can sent along any custom * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more. * This hook can only be used in a child component of `` or ``. * * @template TData Optional typing for the custom user presence data object. Default is `object` type. * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one will be created. * @param initialData Initial presence data object for the user. Can be value or a function to get the value. * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state * will be created, otherwise it will use the existing one. Default value is ":" * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method * to update the local user's presence and the `LivePresence` Fluid object. * * @example ```jsx import { useLivePresence } from "@microsoft/live-share-react"; // Define a unique key that differentiates this usage of `useLivePresence` from others in your app const MY_UNIQUE_KEY = "presence-key"; // Example component for using useLivePresence export const MyCustomPresence = () => { const { allUsers, localUser, livePresence, updatePresence, } = useLivePresence(MY_UNIQUE_KEY, { picture: "DEFAULT_PROFILE_PICTURE_URL", readyToStart: false, }); // Callback to update the user's presence const onToggleReady = () => { updatePresence({ ...localUser.data, readyToStart: !localUser.data.readyToStart, }); } // Render loading UI while loading LivePresence for first time if (!livePresence) return <>Loading...; // Render presence UI return ( {allUsers.map((user) => (
{user.displayName}
{`Ready: ${user.data.readyToStart}`}
{user.isLocalUser && ( )}
))} ); } ``` */ export declare function useLivePresence(uniqueKey: string, initialData: TData | (() => TData), allowedRoles?: UserMeetingRole[]): IUseLivePresenceResults; //# sourceMappingURL=useLivePresence.d.ts.map