|
@@ -163,6 +163,7 @@ const CallBar = ({callStatus,setCallStatus,socket,myVideoRef}:ICallBar) => {
|
|
|
const connectionRef = useRef<any>(null);
|
|
|
const [mySocket, setMySocket] = useState<string>('')
|
|
|
const [companionSocket, setCompanionSocket] = useState<string>('')
|
|
|
+ const [companionSignal, setCompanionSignal] = useState<string>('')
|
|
|
const [name, setName] = useState<string>('')
|
|
|
const [lastName, setLastName] = useState<string>('')
|
|
|
const [avatarUrl, setAvatarUrl] = useState<string>('')
|
|
@@ -194,14 +195,14 @@ const CallBar = ({callStatus,setCallStatus,socket,myVideoRef}:ICallBar) => {
|
|
|
})
|
|
|
setCallStatus('ringing')
|
|
|
});
|
|
|
- // peer.on("stream", (stream: any) => {
|
|
|
- // console.log(stream,'user stream')
|
|
|
- // });
|
|
|
- // socket.on("acceptedCall", ({ signal }: any) => {
|
|
|
- // // peer.signal(signal)
|
|
|
- // setCallStatus('accepted')
|
|
|
- // console.log(signal,'signal accepted from companion')
|
|
|
- // });
|
|
|
+ peer.on("stream", (stream: any) => {
|
|
|
+ console.log(stream,'user stream')
|
|
|
+ });
|
|
|
+ socket.on("acceptedCall", ({ signal }: any) => {
|
|
|
+ peer.signal(signal)
|
|
|
+ setCallStatus('accepted')
|
|
|
+ console.log(signal,'signal accepted from companion')
|
|
|
+ });
|
|
|
connectionRef.current = peer;
|
|
|
},[chat.socketId,chat.companionId,_id,socket,setCallStatus,mySocket])
|
|
|
|
|
@@ -217,14 +218,13 @@ const CallBar = ({callStatus,setCallStatus,socket,myVideoRef}:ICallBar) => {
|
|
|
});
|
|
|
peer.on("signal", (data: any) => {
|
|
|
socket.emit("answerCall", { signal: data, to: companionSocket });
|
|
|
- console.log(data,'sent the signal on answer')
|
|
|
});
|
|
|
- // peer.on("stream", (stream: any) => {
|
|
|
- // console.log(stream,'user stream')
|
|
|
- // });
|
|
|
- // peer.signal();
|
|
|
+ peer.on("stream", (stream: any) => {
|
|
|
+ userVideoRef.current.srcObject = stream;
|
|
|
+ });
|
|
|
+ peer.signal(companionSignal);
|
|
|
connectionRef.current = peer;
|
|
|
- },[socket,companionSocket])
|
|
|
+ },[socket,companionSocket,companionSignal])
|
|
|
|
|
|
useEffect(() => {
|
|
|
socket.on("me", (id: string) => {
|
|
@@ -239,12 +239,9 @@ const CallBar = ({callStatus,setCallStatus,socket,myVideoRef}:ICallBar) => {
|
|
|
setColor(data.color)
|
|
|
setNumber(data.number)
|
|
|
setCompanionSocket(data.from)
|
|
|
- console.log(data,'incomeCall')
|
|
|
- })
|
|
|
- socket.on('acceptedCall', (data: any) => {
|
|
|
- console.log(data,'acceptedCall')
|
|
|
+ setCompanionSignal(data.signal)
|
|
|
})
|
|
|
- },[socket,setCallStatus,setName,setLastName,setCompanionSocket])
|
|
|
+ },[socket,setCallStatus,setName,setLastName,setCompanionSocket,setCompanionSignal])
|
|
|
|
|
|
useEffect(() => {
|
|
|
if(callStatus === 'requesting') handleStartCall()
|