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