/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Microsoft Live Share SDK License. */ import { ContainerSchema, IFluidContainer } from "fluid-framework"; import React from "react"; import { ILiveShareClientOptions, ILiveShareHost, ILiveShareJoinResults, ITimestampProvider } from "@microsoft/live-share"; /** * React Context provider values for ``. * * @remarks * To get the latest values, use the {@link useLiveShareContext} hook. * Use the {@link useFluidObjectsContext} hook for other relevant context values. */ export interface ILiveShareContext { /** * True if the local user created the Fluid container */ created: boolean; /** * True if connected to the Live Share container */ joined: boolean; /** * An error that will be defined if there was a problem joining the container, or undefined if not. */ joinError: Error | undefined; /** * Live Share timestamp provider. Can be used to `.getTimestamp()` for a global clock value. * This reference timestamp value should be fairly consistent for all users in the session. */ timestampProvider: ITimestampProvider | undefined; /** * Join callback method for manually connecting to the Fluid container. * * @remarks * Use this callback if `joinOnLoad` is `false` or `undefined` in {@link ILiveShareProviderProps}. * * @param initialObjects Optional. The initial objects for the Fluid container schema. * @param onInitializeContainer Optional. Callback for when the container is first created. * @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container */ join: (fluidContainerSchema?: ContainerSchema, onInitializeContainer?: (container: IFluidContainer) => void) => Promise; } /** * @hidden */ export declare const LiveShareContext: React.Context; /** * Hook to get the latest React context state for `LiveShareContext`. * * @remarks * This hook can only be used in a child component of ``. * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`. * * @returns current state of `LiveShareContext` * * @example ```jsx // LiveShareApp.jsx import { LiveShareProvider } from "@microsoft/live-share-react"; import { LiveShareHost } from "@microsoft/teams-js"; const host = LiveShareHost.create(); export function LiveShareApp() { // Call app.initialize() from teams-js before rendering LiveShareProvider return ( ); } // LiveShareLoader.jsx import { useLiveShareContext } from "@microsoft/live-share-react"; export function LiveShareLoader({ children }) { const { joined, joinError } = useLiveShareContext(); if (joinError) return <>{joinError.message}; if (!joined) return <>Joining Live Share session...; return <>{children} } // LiveCheckbox.jsx import { useLiveState } from "@microsoft/live-share-react"; export function LiveCheckbox() { const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false); return ( { setChecked(!checked); }} /> ); } ``` */ export declare const useLiveShareContext: () => ILiveShareContext; /** * Prop types for {@link LiveShareProvider} component. */ export interface ILiveShareProviderProps { /** * Optional. React children node for the React Context Provider */ children?: React.ReactNode; /** * Optional. Options for initializing `LiveShareClient`. */ clientOptions?: ILiveShareClientOptions; /** * Host to initialize `LiveShareClient` with. * * @remarks * If using the `LiveShareClient` class from `@microsoft/teams-js`, you must ensure that you have first called `teamsJs.app.initialize()` before calling `LiveShareClient.create()`. */ host: ILiveShareHost; /** * The schema to use when {@link joinOnLoad} is true. */ fluidContainerSchema?: ContainerSchema; /** * Optional. Flag to determine whether to join Fluid container on load. */ joinOnLoad?: boolean; } /** * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`. * * @example ```jsx // LiveShareApp.jsx import { LiveShareProvider } from "@microsoft/live-share-react"; import { LiveShareHost } from "@microsoft/teams-js"; const host = LiveShareHost.create(); export function LiveShareApp() { // Call app.initialize() from teams-js before rendering LiveShareProvider return ( ); } // LiveShareLoader.jsx import { useLiveShareContext } from "@microsoft/live-share-react"; export function LiveShareLoader({ children }) { const { joined, joinError } = useLiveShareContext(); if (joinError) return <>{joinError.message}; if (!joined) return <>Joining Live Share session...; return <>{children} } // LiveCheckbox.jsx import { useLiveState } from "@microsoft/live-share-react"; export function LiveCheckbox() { const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false); return ( { setChecked(!checked); }} /> ); } ``` */ export declare const LiveShareProvider: React.FC; //# sourceMappingURL=LiveShareProvider.d.ts.map