Skip to content

Commit

Permalink
feat: add AgoraRTCScreenShareProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed May 5, 2023
1 parent fc3a90e commit 1b6c9b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/agora-rtc-react/src/hooks/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,30 @@ export function useRTCClient(client?: IAgoraRTCClient | null): IAgoraRTCClient {

return resolvedClient;
}

const AgoraRTCScreenShareContext = /* @__PURE__ */ createContext<IAgoraRTCClient | null>(null);

export interface AgoraRTCScreenShareProviderProps {
readonly client: IAgoraRTCClient;
readonly children?: ReactNode;
}

export function AgoraRTCScreenShareProvider({
client,
children,
}: AgoraRTCScreenShareProviderProps) {
return (
<AgoraRTCScreenShareContext.Provider value={client}>
{children}
</AgoraRTCScreenShareContext.Provider>
);
}

/**
* 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;
}

0 comments on commit 1b6c9b0

Please sign in to comment.