diff --git a/packages/agora-rtc-react/src/hooks/context.tsx b/packages/agora-rtc-react/src/hooks/context.tsx index fee8b699..f3258c1e 100644 --- a/packages/agora-rtc-react/src/hooks/context.tsx +++ b/packages/agora-rtc-react/src/hooks/context.tsx @@ -39,3 +39,30 @@ export function useRTCClient(client?: IAgoraRTCClient | null): IAgoraRTCClient { return resolvedClient; } + +const AgoraRTCScreenShareContext = /* @__PURE__ */ createContext(null); + +export interface AgoraRTCScreenShareProviderProps { + readonly client: IAgoraRTCClient; + readonly children?: ReactNode; +} + +export function AgoraRTCScreenShareProvider({ + client, + children, +}: AgoraRTCScreenShareProviderProps) { + return ( + + {children} + + ); +} + +/** + * Get a screen share client from context. + * @param client If a client is provided, it will be used instead. + */ +export function useRTCScreenShareClient(client?: IAgoraRTCClient | null): IAgoraRTCClient | null { + const clientFromContext = useContext(AgoraRTCScreenShareContext); + return client || clientFromContext; +}