|
@@ -157,8 +157,7 @@ interface ICallBar {
|
|
const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
const classes = useStyles()
|
|
const classes = useStyles()
|
|
const { _id } = useSelector(getAuthorizationState)
|
|
const { _id } = useSelector(getAuthorizationState)
|
|
- const chat = useSelector(getChat)
|
|
|
|
- const { socketId, companionId } = chat
|
|
|
|
|
|
+ const { socketId, companionId, name:_name,lastName:_lastName,avatarUrl:_avatarUrl,color:_color,number:_number } = useSelector(getChat)
|
|
const connectionRef = useRef<any>(null);
|
|
const connectionRef = useRef<any>(null);
|
|
const idAudioIntervalRef = useRef<any>(null);
|
|
const idAudioIntervalRef = useRef<any>(null);
|
|
const myVideoRef = useRef<any>(null);
|
|
const myVideoRef = useRef<any>(null);
|
|
@@ -183,13 +182,11 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
const [audioHtml, setAudioHtml] = useState<any>(null)
|
|
const [audioHtml, setAudioHtml] = useState<any>(null)
|
|
|
|
|
|
const handleLeaveCall = useCallback(() => {
|
|
const handleLeaveCall = useCallback(() => {
|
|
- if (callStatus === 'is calling you') {
|
|
|
|
- socket.emit("answerCall", {
|
|
|
|
- signal: 'declined',
|
|
|
|
- to: companionSocket,
|
|
|
|
- });
|
|
|
|
|
|
+ setCallStatus('hanging up...')
|
|
|
|
+ if (connectionRef.current) {
|
|
|
|
+ connectionRef.current.destroy()
|
|
|
|
+ connectionRef.current = null
|
|
}
|
|
}
|
|
- if(connectionRef.current) connectionRef.current.destroy();
|
|
|
|
if(idAudioIntervalRef.current) clearInterval(idAudioIntervalRef.current)
|
|
if(idAudioIntervalRef.current) clearInterval(idAudioIntervalRef.current)
|
|
myVideoRef.current.srcObject = null
|
|
myVideoRef.current.srcObject = null
|
|
companionVideoRef.current.srcObject = null
|
|
companionVideoRef.current.srcObject = null
|
|
@@ -205,20 +202,19 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
setCompanionSocket('')
|
|
setCompanionSocket('')
|
|
setMyStream(null)
|
|
setMyStream(null)
|
|
setCompanionSignal(null)
|
|
setCompanionSignal(null)
|
|
- setName('')
|
|
|
|
- setLastName('')
|
|
|
|
- setAvatarUrl('')
|
|
|
|
- setColor('')
|
|
|
|
- setNumber('')
|
|
|
|
setCallLast(0)
|
|
setCallLast(0)
|
|
cetConversationLast('')
|
|
cetConversationLast('')
|
|
setFullScreen(false)
|
|
setFullScreen(false)
|
|
setAlert('')
|
|
setAlert('')
|
|
- setCallStatus('')
|
|
|
|
- }, [setCallStatus, callStatus, companionSocket, audioHtml, myStream])
|
|
|
|
-
|
|
|
|
- const handleHangUp = () =>
|
|
|
|
- setCallStatus('hanging up...')
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ setCallStatus('')
|
|
|
|
+ setName('')
|
|
|
|
+ setLastName('')
|
|
|
|
+ setAvatarUrl('')
|
|
|
|
+ setColor('')
|
|
|
|
+ setNumber('')
|
|
|
|
+ },500)
|
|
|
|
+ }, [setCallStatus, audioHtml, myStream])
|
|
|
|
|
|
const handleConversationLast = (e: any) =>
|
|
const handleConversationLast = (e: any) =>
|
|
cetConversationLast(getTimeBySeconds(e.target.currentTime))
|
|
cetConversationLast(getTimeBySeconds(e.target.currentTime))
|
|
@@ -243,11 +239,12 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
}
|
|
}
|
|
replaceStream(shareTrack)
|
|
replaceStream(shareTrack)
|
|
} else {
|
|
} else {
|
|
- setAlert(`You can not enable Share before stream started`)
|
|
|
|
- setTimeout(() => setAlert(''),1000)
|
|
|
|
|
|
+ setAlert(`Can not start Share before ringing`)
|
|
|
|
+ setTimeout(() => setAlert(''),2000)
|
|
}
|
|
}
|
|
} catch (e: any) {
|
|
} catch (e: any) {
|
|
- setCallStatus('permission not allowed')
|
|
|
|
|
|
+ setAlert(`Permission fro getDisplayMedia is required!`)
|
|
|
|
+ setTimeout(() => setAlert(''),2000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -256,8 +253,8 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
setMutedMyVideo(!mutedMyVideo)
|
|
setMutedMyVideo(!mutedMyVideo)
|
|
myStream.getVideoTracks()[0].enabled = !myStream.getVideoTracks()[0].enabled
|
|
myStream.getVideoTracks()[0].enabled = !myStream.getVideoTracks()[0].enabled
|
|
} else {
|
|
} else {
|
|
- setAlert(`You can not ${mutedMyVideo ? 'enable' : 'disable'} Video before stream started`)
|
|
|
|
- setTimeout(() => setAlert(''),1000)
|
|
|
|
|
|
+ setAlert(`Can not ${mutedMyVideo ? 'start' : 'stop'} Video before ringing`)
|
|
|
|
+ setTimeout(() => setAlert(''),2000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -266,8 +263,8 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
setMutedMyAudio(!mutedMyAudio)
|
|
setMutedMyAudio(!mutedMyAudio)
|
|
myStream.getAudioTracks()[0].enabled = !myStream.getAudioTracks()[0].enabled
|
|
myStream.getAudioTracks()[0].enabled = !myStream.getAudioTracks()[0].enabled
|
|
} else {
|
|
} else {
|
|
- setAlert(`You can not ${mutedMyAudio ? 'enable' : 'disable'} Audio before stream started`)
|
|
|
|
- setTimeout(() => setAlert(''),1000)
|
|
|
|
|
|
+ setAlert(`Can not start ${mutedMyAudio ? 'start' : 'stop'} Audio before ringing`)
|
|
|
|
+ setTimeout(() => setAlert(''),2000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -285,13 +282,13 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
trickle: false,
|
|
trickle: false,
|
|
stream
|
|
stream
|
|
});
|
|
});
|
|
|
|
+ setCallStatus('ringing...')
|
|
const audioRing = playNotification(`${prodBaseURL}/calling.mp3`)
|
|
const audioRing = playNotification(`${prodBaseURL}/calling.mp3`)
|
|
audioRing.loop = true
|
|
audioRing.loop = true
|
|
setAudioHtml(audioRing)
|
|
setAudioHtml(audioRing)
|
|
idAudioIntervalRef.current = setInterval(() =>
|
|
idAudioIntervalRef.current = setInterval(() =>
|
|
setCallLast(prevState => prevState + 1), 1000)
|
|
setCallLast(prevState => prevState + 1), 1000)
|
|
peer.on("signal", (data: any) => {
|
|
peer.on("signal", (data: any) => {
|
|
- setCallStatus('ringing...')
|
|
|
|
socket.emit("callTo", {
|
|
socket.emit("callTo", {
|
|
to: socketId,
|
|
to: socketId,
|
|
signalData: data,
|
|
signalData: data,
|
|
@@ -306,39 +303,34 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
companionAudioRef.current.srcObject = companionStream;
|
|
companionAudioRef.current.srcObject = companionStream;
|
|
});
|
|
});
|
|
peer.on('connect', () => {
|
|
peer.on('connect', () => {
|
|
- setCallStatus('connection')
|
|
|
|
- setAlert('')
|
|
|
|
audioRing.pause()
|
|
audioRing.pause()
|
|
|
|
+ setCallStatus('connection')
|
|
clearInterval(idAudioIntervalRef.current)
|
|
clearInterval(idAudioIntervalRef.current)
|
|
- setTimeout(() => setCallStatus('conversation'),1000)
|
|
|
|
|
|
+ setTimeout(() => setCallStatus('conversation'),500)
|
|
})
|
|
})
|
|
- peer.on("close", () => setCallStatus('hanging up...'));
|
|
|
|
- peer.on('error', () => setCallStatus('connection lost'))
|
|
|
|
- socket.on("acceptedCall", ({ signal }: any) => {
|
|
|
|
- if (signal === 'declined') setCallStatus('request declined')
|
|
|
|
- else if (signal === 'busy') setCallStatus('line busy')
|
|
|
|
- else peer.signal(signal)
|
|
|
|
- });
|
|
|
|
|
|
+ peer.on("close", handleLeaveCall);
|
|
|
|
+ peer.on('error', handleLeaveCall)
|
|
|
|
+ socket.on("acceptedCall", ({ signal }: any) => peer.signal(signal));
|
|
connectionRef.current = peer;
|
|
connectionRef.current = peer;
|
|
} catch (e:any) {
|
|
} catch (e:any) {
|
|
- setCallStatus('permission not allowed')
|
|
|
|
|
|
+ handleLeaveCall()
|
|
}
|
|
}
|
|
- },[socketId,companionId,_id,mySocket,myVideoRef,setCallStatus])
|
|
|
|
|
|
+ },[socketId,companionId,_id,mySocket,myVideoRef,setCallStatus,handleLeaveCall])
|
|
|
|
|
|
const handleAnswerCall = useCallback(async () => {
|
|
const handleAnswerCall = useCallback(async () => {
|
|
try {
|
|
try {
|
|
- setCallStatus('waiting...')
|
|
|
|
audioHtml.pause()
|
|
audioHtml.pause()
|
|
- const stream = await navigator.mediaDevices.getUserMedia({
|
|
|
|
- video: true,
|
|
|
|
- audio: true
|
|
|
|
- })
|
|
|
|
- setMyStream(stream)
|
|
|
|
- myVideoRef.current.srcObject = stream;
|
|
|
|
|
|
+ setCallStatus('waiting...')
|
|
|
|
+ // const stream = await navigator.mediaDevices.getUserMedia({
|
|
|
|
+ // video: true,
|
|
|
|
+ // audio: true
|
|
|
|
+ // })
|
|
|
|
+ // setMyStream(stream)
|
|
|
|
+ // myVideoRef.current.srcObject = stream;
|
|
const peer = new Peer({
|
|
const peer = new Peer({
|
|
initiator: false,
|
|
initiator: false,
|
|
trickle: false,
|
|
trickle: false,
|
|
- stream,
|
|
|
|
|
|
+ stream: false,
|
|
});
|
|
});
|
|
peer.on("signal", (data: any) => {
|
|
peer.on("signal", (data: any) => {
|
|
socket.emit("answerCall", {
|
|
socket.emit("answerCall", {
|
|
@@ -352,17 +344,16 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
});
|
|
});
|
|
peer.on('connect', () => {
|
|
peer.on('connect', () => {
|
|
setCallStatus('connection')
|
|
setCallStatus('connection')
|
|
- setAlert('')
|
|
|
|
- setTimeout(() => setCallStatus('conversation'),1000)
|
|
|
|
|
|
+ setTimeout(() => setCallStatus('conversation'),500)
|
|
})
|
|
})
|
|
- peer.on("close", () => setCallStatus('hanging up...'));
|
|
|
|
- peer.on('error', () => setCallStatus('connection lost'))
|
|
|
|
|
|
+ peer.on("close", handleLeaveCall);
|
|
|
|
+ peer.on('error', handleLeaveCall)
|
|
peer.signal(companionSignal);
|
|
peer.signal(companionSignal);
|
|
connectionRef.current = peer;
|
|
connectionRef.current = peer;
|
|
- } catch (e: any) {
|
|
|
|
- setCallStatus('permission not allowed')
|
|
|
|
|
|
+ } catch (e:any) {
|
|
|
|
+ handleLeaveCall()
|
|
}
|
|
}
|
|
- }, [companionSocket, companionSignal, setCallStatus,audioHtml])
|
|
|
|
|
|
+ }, [companionSocket, companionSignal, setCallStatus,audioHtml,handleLeaveCall])
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
socket.on("me", (id: string) => {
|
|
socket.on("me", (id: string) => {
|
|
@@ -374,7 +365,6 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
socket.on('incomeCall', ({ name, lastName, avatarUrl, color, number, from, signal }: any) => {
|
|
socket.on('incomeCall', ({ name, lastName, avatarUrl, color, number, from, signal }: any) => {
|
|
if (connectionRef.current === null) {
|
|
if (connectionRef.current === null) {
|
|
- setCallStatus('is calling you')
|
|
|
|
setName(name)
|
|
setName(name)
|
|
setLastName(lastName)
|
|
setLastName(lastName)
|
|
setAvatarUrl(avatarUrl)
|
|
setAvatarUrl(avatarUrl)
|
|
@@ -385,39 +375,25 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
const audioRing = playNotification(`${prodBaseURL}/ringing.mp3`)
|
|
const audioRing = playNotification(`${prodBaseURL}/ringing.mp3`)
|
|
audioRing.loop = true
|
|
audioRing.loop = true
|
|
setAudioHtml(audioRing)
|
|
setAudioHtml(audioRing)
|
|
- } else if (companionSocket !== from) {
|
|
|
|
- socket.emit("answerCall", {
|
|
|
|
- signal: 'busy',
|
|
|
|
- to: companionSocket,
|
|
|
|
- });
|
|
|
|
|
|
+ setCallStatus('is calling you')
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}, [setCallStatus,companionSocket])
|
|
}, [setCallStatus,companionSocket])
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (callLast === 60) setCallStatus('have not got response')
|
|
|
|
- }, [callLast, setCallStatus])
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if(callStatus === 'requesting...') handleStartCall()
|
|
|
|
- }, [callStatus, handleStartCall])
|
|
|
|
|
|
+ if (callStatus === 'requesting...') {
|
|
|
|
+ setName(_name)
|
|
|
|
+ setLastName(_lastName)
|
|
|
|
+ setAvatarUrl(_avatarUrl)
|
|
|
|
+ setColor(_color)
|
|
|
|
+ setNumber(_number)
|
|
|
|
+ setTimeout(handleStartCall,500)
|
|
|
|
+ }
|
|
|
|
+ }, [callStatus,_name,_lastName,_avatarUrl,_color,_number, handleStartCall])
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (callStatus === 'hanging up...' || callStatus === 'connection lost'
|
|
|
|
- || callStatus === 'request declined' || callStatus === 'have not got response'
|
|
|
|
- || callStatus === 'permission not allowed' || callStatus === 'line busy')
|
|
|
|
- handleLeaveCall()
|
|
|
|
- }, [callStatus, handleLeaveCall, setCallStatus])
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (callStatus === '') {
|
|
|
|
- setName(chat.name)
|
|
|
|
- setLastName(chat.lastName)
|
|
|
|
- setAvatarUrl(chat.avatarUrl)
|
|
|
|
- setColor(chat.color)
|
|
|
|
- setNumber(chat.number)
|
|
|
|
- }
|
|
|
|
- }, [callStatus, chat])
|
|
|
|
|
|
+ if (callLast === 60) handleLeaveCall()
|
|
|
|
+ }, [callLast, handleLeaveCall])
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className={classes.container} style={{ top: callStatus ? 0 : '-100%'}}>
|
|
<div className={classes.container} style={{ top: callStatus ? 0 : '-100%'}}>
|
|
@@ -444,7 +420,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
style={{backgroundColor:fullScreen?'rgb(70, 70, 70)':'rgb(36, 36, 36)'}}>
|
|
style={{backgroundColor:fullScreen?'rgb(70, 70, 70)':'rgb(36, 36, 36)'}}>
|
|
<CropLandscapeIcon fontSize='small' />
|
|
<CropLandscapeIcon fontSize='small' />
|
|
</div>
|
|
</div>
|
|
- <div className={classes.rightIconWrapperClose} onClick={handleHangUp}>
|
|
|
|
|
|
+ <div className={classes.rightIconWrapperClose} onClick={handleLeaveCall}>
|
|
<CloseIcon fontSize='small' />
|
|
<CloseIcon fontSize='small' />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -486,7 +462,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
<Typography variant="h6" className={classes.titleIconBottom}>{mutedMyVideo?'Start Video':'Stop Video'}</Typography>
|
|
<Typography variant="h6" className={classes.titleIconBottom}>{mutedMyVideo?'Start Video':'Stop Video'}</Typography>
|
|
</div>
|
|
</div>
|
|
<div className={classes.bottomItem}>
|
|
<div className={classes.bottomItem}>
|
|
- <Avatar className={classes.bottomIconEndAccept} onClick={handleHangUp}
|
|
|
|
|
|
+ <Avatar className={classes.bottomIconEndAccept} onClick={handleLeaveCall}
|
|
sx={{backgroundColor: '#f02a2a',color: '#ffffff', width: 44, height: 44,zIndex:0}}>
|
|
sx={{backgroundColor: '#f02a2a',color: '#ffffff', width: 44, height: 44,zIndex:0}}>
|
|
<CallEndIcon fontSize="medium" />
|
|
<CallEndIcon fontSize="medium" />
|
|
</Avatar>
|
|
</Avatar>
|