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