/** * useWebRTC Hook * * React hook for managing WebRTC video calling with peer connections, * local/remote streams, and signaling integration. * * This hook provides all the functionality needed for 1-to-1 video calls. * Users are responsible for implementing their own signaling mechanism * (WebSocket, Socket.io, etc.) to exchange SDP offers/answers and ICE candidates. */ import { useState, useCallback, useRef, useEffect } from 'react'; import { WebRTCManager, isWebRTCAvailable, } from '../webrtc/WebRTCManager'; import type { UseWebRTCOptions, UseWebRTCResult, PeerConnectionConfig, MediaConstraints, SessionDescription, ICECandidateEvent, CallState, WebRTCConnectionState, ICEConnectionState, } from '../webrtc/types'; /** * Hook for WebRTC video calling * * @param options - Configuration options * @returns WebRTC controls and state * * @example * ```tsx * import { useWebRTC } from '@arfuhad/react-native-smart-camera'; * import { RTCView } from 'react-native-webrtc'; * * function VideoCall() { * const { * localStream, * remoteStream, * callState, * startLocalStream, * createPeerConnection, * createOffer, * setRemoteDescription, * addIceCandidate, * onIceCandidate, * switchCamera, * toggleAudio, * toggleVideo, * cleanup, * } = useWebRTC({ * config: { * iceServers: [{ urls: 'stun:stun.l.google.com:19302' }], * }, * onRemoteStream: (stream) => console.log('Remote stream received'), * }); * * // Start a call * const startCall = async () => { * await startLocalStream(); * createPeerConnection(); * const offer = await createOffer(); * // Send offer via your signaling server * socket.emit('offer', offer); * }; * * // Handle incoming call * useEffect(() => { * socket.on('offer', async (offer) => { * await startLocalStream(); * createPeerConnection(); * await setRemoteDescription(offer); * const answer = await createAnswer(); * socket.emit('answer', answer); * }); * * socket.on('ice-candidate', (candidate) => { * addIceCandidate(candidate); * }); * * onIceCandidate((event) => { * if (event.candidate) { * socket.emit('ice-candidate', event.candidate); * } * }); * }, []); * * return ( * * {remoteStream && } * {localStream && } *