|
@@ -22,7 +22,7 @@ import Alert from '@mui/material/Alert';
|
|
|
import { getChat } from '../../../redux/chat/selector';
|
|
|
import { getAuthorizationState } from '../../../redux/authorization/selector';
|
|
|
import { prodAwsS3,prodBaseURL,prodSocketURL, firstLetter, slicedWord,getTimeBySeconds,playNotification } from '../../../helpers'
|
|
|
-import { socketIdChat,sentMessageCallById } from '../../../api-data';
|
|
|
+import { socketIdChat, sentMessageCallById , updateMessageCallById } from '../../../api-data';
|
|
|
|
|
|
const Peer = require('simple-peer')
|
|
|
const socket = io(prodSocketURL)
|
|
@@ -163,6 +163,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
const companionVideoRef = useRef<any>(null);
|
|
|
const companionAudioRef = useRef<any>(null);
|
|
|
const idAudioIntervalRef = useRef<any>(null);
|
|
|
+ const [callMsgId, setCallMsgId] = useState<string>('')
|
|
|
const [mySocket, setMySocket] = useState<string>('')
|
|
|
const [myStream, setMyStream] = useState<any>(null)
|
|
|
const [myShareStream, setMyShareStream] = useState<any>(null)
|
|
@@ -172,7 +173,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
const [companionSignal, setCompanionSignal] = useState<any>(null)
|
|
|
const [audioHtml, setAudioHtml] = useState<any>(null)
|
|
|
const [callLast, setCallLast] = useState<number>(0)
|
|
|
- const [conversationLast, cetConversationLast] = useState<string>('')
|
|
|
+ const [conversationLast, setConversationLast] = useState<number>(0)
|
|
|
const [fullScreen, setFullScreen] = useState<boolean>(false)
|
|
|
const [alert, setAlert] = useState<string>('')
|
|
|
const [name, setName] = useState<string>('')
|
|
@@ -195,7 +196,9 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
audioHtml.pause()
|
|
|
setAudioHtml(null)
|
|
|
}
|
|
|
- if(myStream) myStream.getTracks().forEach((track:any) => track.stop())
|
|
|
+ if (myStream) myStream.getTracks().forEach((track: any) => track.stop())
|
|
|
+ if (callMsgId) updateMessageCallById(callMsgId, conversationLast)
|
|
|
+ setCallMsgId('')
|
|
|
setMyShareStream(null)
|
|
|
setMutedMyVideo(false)
|
|
|
setMutedMyAudio(false)
|
|
@@ -203,7 +206,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
setMyStream(null)
|
|
|
setCompanionSignal(null)
|
|
|
setCallLast(0)
|
|
|
- cetConversationLast('')
|
|
|
+ setConversationLast(0)
|
|
|
setFullScreen(false)
|
|
|
setAlert('')
|
|
|
setTimeout(() => {
|
|
@@ -214,10 +217,9 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
setColor('')
|
|
|
setNumber('')
|
|
|
},500)
|
|
|
- }, [setCallStatus, audioHtml, myStream])
|
|
|
+ }, [setCallStatus, audioHtml, myStream,callMsgId,conversationLast])
|
|
|
|
|
|
- const handleConversationLast = (e: any) =>
|
|
|
- cetConversationLast(getTimeBySeconds(e.target.currentTime))
|
|
|
+ const handleConversationLast = (e: any) => setConversationLast(e.target.currentTime)
|
|
|
|
|
|
const handleMuteShare = async () => {
|
|
|
try {
|
|
@@ -270,7 +272,6 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
|
|
|
const handleStartCall = useCallback(async () => {
|
|
|
try {
|
|
|
- sentMessageCallById(companionId,false,0)
|
|
|
setCallStatus('waiting...')
|
|
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
|
video: true,
|
|
@@ -282,7 +283,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
const peer = new Peer({
|
|
|
initiator: true,
|
|
|
trickle: false,
|
|
|
- stream
|
|
|
+ stream,
|
|
|
});
|
|
|
setCallStatus('ringing...')
|
|
|
const audioRing = playNotification(`${prodBaseURL}/calling.mp3`)
|
|
@@ -297,7 +298,6 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
from: mySocket,
|
|
|
userId: _id,
|
|
|
companionId,
|
|
|
- peer
|
|
|
})
|
|
|
});
|
|
|
peer.on("stream", (companionStream: any) => {
|
|
@@ -324,17 +324,17 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
try {
|
|
|
audioHtml.pause()
|
|
|
setCallStatus('waiting...')
|
|
|
- // const stream = await navigator.mediaDevices.getUserMedia({
|
|
|
- // video: true,
|
|
|
- // audio: true
|
|
|
- // })
|
|
|
- //stream.getVideoTracks()[0].enabled = false
|
|
|
- // setMyStream(stream)
|
|
|
- // myVideoRef.current.srcObject = stream;
|
|
|
+ const stream = await navigator.mediaDevices.getUserMedia({
|
|
|
+ video: true,
|
|
|
+ audio: true
|
|
|
+ })
|
|
|
+ stream.getVideoTracks()[0].enabled = false
|
|
|
+ setMyStream(stream)
|
|
|
+ myVideoRef.current.srcObject = stream;
|
|
|
const peer = new Peer({
|
|
|
initiator: false,
|
|
|
trickle: false,
|
|
|
- stream: false,
|
|
|
+ stream,
|
|
|
});
|
|
|
peer.on("signal", (data: any) => {
|
|
|
socket.emit("answerCall", {
|
|
@@ -389,15 +389,17 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
}, [setCallStatus,companionSocket])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (callStatus === 'requesting...') {
|
|
|
+ if (callStatus === 'requesting...' && callMsgId === '') {
|
|
|
setName(_name)
|
|
|
setLastName(_lastName)
|
|
|
setAvatarUrl(_avatarUrl)
|
|
|
setColor(_color)
|
|
|
setNumber(_number)
|
|
|
- setTimeout(handleStartCall,500)
|
|
|
+ sentMessageCallById(companionId, 0)
|
|
|
+ .then((data: any) => setCallMsgId(data._id))
|
|
|
+ setTimeout(handleStartCall, 500)
|
|
|
}
|
|
|
- }, [callStatus,_name,_lastName,_avatarUrl,_color,_number, handleStartCall])
|
|
|
+ }, [callStatus,callMsgId,_name,_lastName,_avatarUrl,_color,_number,companionId, handleStartCall])
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (callLast === 60) handleLeaveCall()
|
|
@@ -447,7 +449,7 @@ const CallBar = ({callStatus,setCallStatus}:ICallBar) => {
|
|
|
primaryTypographyProps={{ color: '#dfdfdf', fontSize: 20, fontWeight: 500,textAlign: "center" }}/>
|
|
|
<ListItemText primary={number} primaryTypographyProps={{ color: '#ffffff', fontSize: 15, fontWeight: 500, textAlign: "center" }} />
|
|
|
<ListItemText secondary={callStatus} secondaryTypographyProps={{ color: "#dfdfdf", textAlign: "center" }} />
|
|
|
- <ListItemText secondary={conversationLast} secondaryTypographyProps={{ color: "#dfdfdf", textAlign: "center" }} />
|
|
|
+ {conversationLast&&<ListItemText secondary={getTimeBySeconds(conversationLast)} secondaryTypographyProps={{ color: "#dfdfdf", textAlign: "center" }} />}
|
|
|
</>}
|
|
|
</div>
|
|
|
<video ref={companionVideoRef} playsInline muted autoPlay controls={false}
|