UNPKG

react-native-whip-whep

Version:

An implementation of WHIP and WHEP protocols functionalities for React Native.

36 lines 1.82 kB
import { useState, useEffect } from "react"; import ReactNativeMobileWhepClientViewModule, { ReceivableEvents, } from "../ReactNativeMobileWhepClientViewModule"; import ReactNativeMobileWhipClientViewModule, { ReceivableEvents as WhipReceivableEvents, } from "../ReactNativeMobileWhipClientViewModule"; /** * Hook that returns the current state of the WHEP peer connection. * If WHEP client was not created, it will return "unknown". */ export const useWhepConnectionState = () => { const [peerConnectionState, setPeerConnectionState] = useState((ReactNativeMobileWhepClientViewModule.whepPeerConnectionState ?? "unknown")); useEffect(() => { const eventListener = ReactNativeMobileWhepClientViewModule.addListener(ReceivableEvents.WhepPeerConnectionStateChanged, (event) => { const payload = event[ReceivableEvents.WhepPeerConnectionStateChanged]; setPeerConnectionState(payload); }); return () => eventListener.remove(); }, []); return peerConnectionState; }; /** * Hook that returns the current state of the WHIP peer connection. * If WHIP client was not created, it will return "unknown". */ export const useWhipConnectionState = () => { const [peerConnectionState, setPeerConnectionState] = useState((ReactNativeMobileWhipClientViewModule.whipPeerConnectionState ?? "unknown")); useEffect(() => { const eventListener = ReactNativeMobileWhipClientViewModule.addListener(WhipReceivableEvents.WhipPeerConnectionStateChanged, (event) => { const payload = event[WhipReceivableEvents.WhipPeerConnectionStateChanged]; setPeerConnectionState(payload); }); return () => eventListener.remove(); }, []); return peerConnectionState; }; //# sourceMappingURL=useConnectionState.js.map