mediasfu-reactnative-expo
Version:
mediasfu-reactnative-expo – Expo-managed React Native WebRTC SDK for video conferencing, webinars, live streaming, broadcast, screen sharing, whiteboard, chat, recording, live subtitles, translation, and AI agent rooms on iOS, Android, and web. Prebuilt r
50 lines • 1.85 kB
JavaScript
/**
* Context for providing live subtitles to video/audio cards.
*
* This allows cards to reactively access subtitle data without
* needing to re-render the entire grid when subtitles change.
*/
import React, { createContext, useContext, useMemo } from 'react';
import { getSubtitleForSpeaker as resolveSubtitleForSpeaker, } from 'mediasfu-shared';
const LiveSubtitleContext = createContext(null);
export const LiveSubtitleProvider = ({ liveSubtitles, showSubtitlesOnCards, children, }) => {
const getSubtitleForSpeaker = useMemo(() => {
return (speakerId, speakerName) => {
return resolveSubtitleForSpeaker(liveSubtitles, speakerId, speakerName) || null;
};
}, [liveSubtitles]);
const value = useMemo(() => ({
liveSubtitles,
showSubtitlesOnCards,
getSubtitleForSpeaker,
}), [liveSubtitles, showSubtitlesOnCards, getSubtitleForSpeaker]);
return (<LiveSubtitleContext.Provider value={value}>
{children}
</LiveSubtitleContext.Provider>);
};
/**
* Hook to access live subtitle context.
* Returns null if used outside of LiveSubtitleProvider.
*/
export const useLiveSubtitles = () => {
return useContext(LiveSubtitleContext);
};
/**
* Hook to get subtitle for a specific speaker.
* Returns null if no subtitle exists or context is unavailable.
*/
export const useSpeakerSubtitle = (speakerId, speakerName) => {
const context = useContext(LiveSubtitleContext);
if (!context)
return null;
return context.getSubtitleForSpeaker(speakerId, speakerName);
};
/**
* Hook to check if subtitles should be shown.
*/
export const useShowSubtitles = () => {
const context = useContext(LiveSubtitleContext);
return context?.showSubtitlesOnCards ?? false;
};
export default LiveSubtitleContext;
//# sourceMappingURL=LiveSubtitleContext.js.map