/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Microsoft Live Share SDK License. */ import { UserMeetingRole } from "@microsoft/live-share"; import { IUseLiveFollowModeResults } from "../types/index.js"; /** * React hook for using a Live Share `LiveFollowMode`. * * @remarks * Use this hook if you want to add the ability to follow specific users or let a user present to everyone in the session. * Each user has their own `stateValue`, which is the value other users will reference when that user is presenting or being followed. * The `state` response includes the user's `value` that the local user is "following", whether it be their own or someone else's. * 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 `LiveFollowMode`. If one does not yet exist, a new one will be created. * @param initialData The initial value for the local user's `stateValue`. * @param allowedRoles Optional. The user roles that are allowed to present to use `startPresenting()` or `stopPresenting()`. * @returns `IUseLiveFollowModeResults` results, which contains React stateful objects and callbacks. * * @example ```jsx import { FollowModeType } from "@microsoft/live-share"; import { useLiveFollowMode } from "@microsoft/live-share-react"; // As an example, we will use a fake component to denote what a 3D viewer might look like in an app import { Example3DModelViewer } from "./components"; // Define a unique key that differentiates this usage of `useLiveFollowMode` from others in your app const MY_UNIQUE_KEY = "follow-mode-key"; // Define the initial stateValue for the local user (optional). const startingCameraPosition = { x: 0, y: 0, z: 0, }; // Example component for using useLiveFollowMode export function MyLiveFollowMode() { const { state, localUser, otherUsers, allUsers, liveFollowMode, update, startPresenting, stopPresenting, beginSuspension, endSuspension, followUser, stopFollowing, } = useLiveFollowMode(MY_UNIQUE_KEY, startingCameraPosition); // Example of an event listener for a camera position changed event. // For something like a camera change event, you should use a debounce function. function onCameraPositionChanged(position, isUserAction) { // Broadcast change to other users so that they have their latest camera position update(position); // If the local user changed the position while following another user, we want to suspend. // Note: helps to distinguish changes initiated by the local user (e.g., drag mouse) separately from other change events. if (!isUserAction) return; switch (state.type) { case FollowModeType.followPresenter: case FollowModeType.followUser: { // This will trigger a "stateChanged" event update for the local user only. followMode.beginSuspension(); break; } default: { // No need to suspend for other types break; } } } // Can optionally get the relevant user's presence object const followingUser = liveFollowMode?.getUser(state.followingUserId); // Render loading UI when creating LiveFollowMode instance for first time if (!liveFollowMode) return <>Loading...; // Render UI return (
{state.type === FollowModeType.local && (

{""}

)} {state.type === FollowModeType.activeFollowers && (

{`${state.otherUsersCount} users are following you`}

)} {state.type === FollowModeType.activePresenter && (

{`You are actively presenting to everyone`}

)} {state.type === FollowModeType.followPresenter && (

{`${followingUser?.displayName} is presenting to everyone`}

)} {state.type === FollowModeType.suspendFollowPresenter && (

{`${followingUser?.displayName} is presenting to everyone`}

)} {state.type === FollowModeType.followUser && (

{`You are following ${followingUser?.displayName}`}

)} {state.type === FollowModeType.suspendFollowUser && (

{`You were following ${followingUser?.displayName}`}

)}

{"Follow a specific user:"}

{otherUsers.map((user) => ( ))}
); }; ``` */ export declare function useLiveFollowMode(uniqueKey: string, initialData: TData | (() => TData), allowedRoles?: UserMeetingRole[]): IUseLiveFollowModeResults; //# sourceMappingURL=useLiveFollowMode.d.ts.map