import { Room } from '../../core/room.js'; /** * RoomPromise is a wrapper around a promise that resolves to a Room instance. * * It is designed to better integrate into the React lifecycle, and control whether an unmount * function needs to be called depending on where the promise resolution occurs relative to the * component lifecycle. */ export interface RoomPromise { /** * Returns a function to be called when the component is unmounted. If the room promise has resolved at the time, * of calling, then the unmount function returned by the onResolve callback will be called. * * Multiple calls are no-op. * * This should be used in conjunction with React's useEffect hook to ensure that resources are cleaned up. * @returns A function that should be called when the component is unmounted. * @example * ```ts * useEffect(() => { * const roomPromise: RoomPromise; * return roomPromise.unmount(); * }, []); */ unmount: () => () => void; } /** * A callback that can be returned by the onResolve callback to clean up any resources. */ type UnmountCallback = () => void; /** * A callback that is called when the promise resolves to a Room instance. */ export type RoomResolutionCallback = (room: Room) => UnmountCallback; export {};