|
@@ -18,7 +18,7 @@ import Picker from 'emoji-picker-react';
|
|
import InputAdornment from '@mui/material/InputAdornment';
|
|
import InputAdornment from '@mui/material/InputAdornment';
|
|
|
|
|
|
import { useReactMediaRecorder } from "react-media-recorder";
|
|
import { useReactMediaRecorder } from "react-media-recorder";
|
|
-import { useState,useEffect } from "react";
|
|
|
|
|
|
+import { useState,useEffect,useCallback } from "react";
|
|
import { useSelector } from "react-redux";
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
|
import FilesMenu from "../FilesMenu";
|
|
import FilesMenu from "../FilesMenu";
|
|
@@ -325,8 +325,10 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
const [isFilming, setIsFilming] = useState<boolean>(false)
|
|
const [isFilming, setIsFilming] = useState<boolean>(false)
|
|
const [isOpenCamera, setIsOpenCamera] = useState<boolean>(false)
|
|
const [isOpenCamera, setIsOpenCamera] = useState<boolean>(false)
|
|
const [type, setType] = useState<string>('')
|
|
const [type, setType] = useState<string>('')
|
|
- const { status, startRecording, stopRecording, mediaBlobUrl, clearBlobUrl } = useReactMediaRecorder({ audio: true,blobPropertyBag:{type: "audio/mp3"}});
|
|
|
|
- const { status: _status, startRecording: _startRecording, stopRecording: _stopRecording,
|
|
|
|
|
|
+ const [status, setStatus] = useState<string | null>(null)
|
|
|
|
+ const [_status, _setStatus] = useState<string | null>(null)
|
|
|
|
+ const { startRecording, stopRecording, mediaBlobUrl, clearBlobUrl, } = useReactMediaRecorder({ audio: true,blobPropertyBag:{type: "audio/mp3"}});
|
|
|
|
+ const { startRecording: _startRecording, stopRecording: _stopRecording,
|
|
mediaBlobUrl: _mediaBlobUrl, clearBlobUrl: _clearBlobUrl } = useReactMediaRecorder({ video: true, blobPropertyBag: { type: "video/mp4" } });
|
|
mediaBlobUrl: _mediaBlobUrl, clearBlobUrl: _clearBlobUrl } = useReactMediaRecorder({ video: true, blobPropertyBag: { type: "video/mp4" } });
|
|
const videoConstraints = {
|
|
const videoConstraints = {
|
|
width: 1280,
|
|
width: 1280,
|
|
@@ -344,25 +346,27 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
}
|
|
}
|
|
};
|
|
};
|
|
const clearMessage = () => {
|
|
const clearMessage = () => {
|
|
- file && setFile(false)
|
|
|
|
- isRecording && setIsRecording(false)
|
|
|
|
- isFilming && setIsFilming(false)
|
|
|
|
- value && setValue('')
|
|
|
|
- caption&& setCaption('')
|
|
|
|
- type && setType('')
|
|
|
|
- mediaBlobUrl && clearBlobUrl()
|
|
|
|
- _mediaBlobUrl && _clearBlobUrl()
|
|
|
|
- isOpenMenu && setIsOpenMenu(false)
|
|
|
|
- isOpenEmoji && setIsOpenEmoji(false)
|
|
|
|
- isOpenCaption && setIsOpenCaption(false)
|
|
|
|
- isOpenCaptionEmoji && setIsOpenCaptionEmoji(false)
|
|
|
|
|
|
+ setFile(false)
|
|
|
|
+ setIsRecording(false)
|
|
|
|
+ setIsFilming(false)
|
|
|
|
+ setValue('')
|
|
|
|
+ setCaption('')
|
|
|
|
+ setType('')
|
|
|
|
+ clearBlobUrl()
|
|
|
|
+ _clearBlobUrl()
|
|
|
|
+ setIsOpenMenu(false)
|
|
|
|
+ setIsOpenEmoji(false)
|
|
|
|
+ setIsOpenCaption(false)
|
|
|
|
+ setIsOpenCaptionEmoji(false)
|
|
|
|
+ setStatus(null)
|
|
|
|
+ _setStatus(null)
|
|
}
|
|
}
|
|
|
|
|
|
const sentMessage = async () => {
|
|
const sentMessage = async () => {
|
|
if (value && !isReply) sentMessageById(companionId, value, caption.trim())
|
|
if (value && !isReply) sentMessageById(companionId, value, caption.trim())
|
|
if (value && isReply) {
|
|
if (value && isReply) {
|
|
sentMessageReplyById(isReply._id, value, caption.trim())
|
|
sentMessageReplyById(isReply._id, value, caption.trim())
|
|
- isReply&&setIsReply(undefined)
|
|
|
|
|
|
+ setIsReply(undefined)
|
|
}
|
|
}
|
|
if (mediaBlobUrl && type === 'recording') {
|
|
if (mediaBlobUrl && type === 'recording') {
|
|
const audio = new XMLHttpRequest();
|
|
const audio = new XMLHttpRequest();
|
|
@@ -450,14 +454,24 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const handleRecording = () => {
|
|
const handleRecording = () => {
|
|
- if (isRecording) return stopRecording()
|
|
|
|
|
|
+ if (isRecording) {
|
|
|
|
+ setStatus('stopped')
|
|
|
|
+ stopRecording()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
startRecording()
|
|
startRecording()
|
|
|
|
+ setStatus('recording')
|
|
setType('recording')
|
|
setType('recording')
|
|
setIsRecording(true)
|
|
setIsRecording(true)
|
|
}
|
|
}
|
|
const handleFilming = () => {
|
|
const handleFilming = () => {
|
|
- if (isFilming) return _stopRecording()
|
|
|
|
|
|
+ if (isFilming) {
|
|
|
|
+ _setStatus('stopped')
|
|
|
|
+ _stopRecording()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
_startRecording()
|
|
_startRecording()
|
|
|
|
+ _setStatus('recording')
|
|
setType('filming')
|
|
setType('filming')
|
|
setIsFilming(true)
|
|
setIsFilming(true)
|
|
}
|
|
}
|
|
@@ -478,26 +492,34 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
setIsReply(undefined)
|
|
setIsReply(undefined)
|
|
clearMessage()
|
|
clearMessage()
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ const defaultState = useCallback(() => {
|
|
|
|
+ stopRecording()
|
|
|
|
+ _stopRecording()
|
|
|
|
+ clearBlobUrl()
|
|
|
|
+ _clearBlobUrl()
|
|
|
|
+ setStatus(null)
|
|
|
|
+ _setStatus(null)
|
|
|
|
+ setIsRecording(false)
|
|
|
|
+ setIsFilming(false)
|
|
|
|
+ setFile(false)
|
|
|
|
+ setValue('')
|
|
|
|
+ setCaption('')
|
|
|
|
+ setType('')
|
|
|
|
+ setIsOpenMenu(false)
|
|
|
|
+ setIsOpenEmoji(false)
|
|
|
|
+ setIsOpenCaption(false)
|
|
|
|
+ setIsOpenCaptionEmoji(false)
|
|
|
|
+ },[_clearBlobUrl,clearBlobUrl,_stopRecording,stopRecording])
|
|
|
|
+
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (isReply) {
|
|
|
|
- stopRecording()
|
|
|
|
- _stopRecording()
|
|
|
|
- clearBlobUrl()
|
|
|
|
- _clearBlobUrl()
|
|
|
|
- setIsRecording(false)
|
|
|
|
- setIsFilming(false)
|
|
|
|
- setFile(false)
|
|
|
|
- setValue('')
|
|
|
|
- setCaption('')
|
|
|
|
- setType('')
|
|
|
|
- setIsOpenMenu(false)
|
|
|
|
- setIsOpenEmoji(false)
|
|
|
|
- setIsOpenCaption(false)
|
|
|
|
- setIsOpenCaptionEmoji(false)
|
|
|
|
- }
|
|
|
|
|
|
+ defaultState()
|
|
}, [isReply])
|
|
}, [isReply])
|
|
- console.log(file,'file', status ,'status', _status, '_status')
|
|
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ defaultState()
|
|
|
|
+ },[companionId])
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={value || file || status === 'stopped' || _status === 'stopped' ?classes.containerActive:classes.container}>
|
|
<div className={value || file || status === 'stopped' || _status === 'stopped' ?classes.containerActive:classes.container}>
|
|
{isArrow && <div className={classes.borderTop}></div>}
|
|
{isArrow && <div className={classes.borderTop}></div>}
|
|
@@ -546,20 +568,20 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
|| (_status === 'stopped'&&type) ? 'inline-block' : 'none'}} />
|
|
|| (_status === 'stopped'&&type) ? 'inline-block' : 'none'}} />
|
|
<VideocamIcon onClick={handleFilming} className={classes.avatarCamera}
|
|
<VideocamIcon onClick={handleFilming} className={classes.avatarCamera}
|
|
sx={{backgroundColor: '#ffffff', color: '#6b6b6b', width: 56, height: 56}}
|
|
sx={{backgroundColor: '#ffffff', color: '#6b6b6b', width: 56, height: 56}}
|
|
- style={{ display: status !== 'idle' || _status === 'stopped' || file || value || isFilming || isReply ? 'none' : 'block' }} />
|
|
|
|
|
|
+ style={{ display: status !== null || _status === 'stopped' || file || value || isFilming || isReply ? 'none' : 'block' }} />
|
|
<SendIcon onClick={sentMessage} className={classes.avatarRight}
|
|
<SendIcon onClick={sentMessage} className={classes.avatarRight}
|
|
sx={{backgroundColor: '#ffffff',color: 'rgb(41, 139, 231)', width: 56, height: 56}}
|
|
sx={{backgroundColor: '#ffffff',color: 'rgb(41, 139, 231)', width: 56, height: 56}}
|
|
style={{display: value || file || status === 'stopped' || _status === 'stopped' ? 'block':'none' }}/>
|
|
style={{display: value || file || status === 'stopped' || _status === 'stopped' ? 'block':'none' }}/>
|
|
<MicNoneIcon onClick={handleRecording} className={classes.avatarRight}
|
|
<MicNoneIcon onClick={handleRecording} className={classes.avatarRight}
|
|
sx={{backgroundColor:'#ffffff',color: '#6b6b6b', width: 56, height: 56}}
|
|
sx={{backgroundColor:'#ffffff',color: '#6b6b6b', width: 56, height: 56}}
|
|
- style={{display: !value && !file && status !== 'stopped' && _status === 'idle'&&!isRecording && !isReply ? 'block' : 'none'}}/>
|
|
|
|
|
|
+ style={{display: !value && !file && status !== 'stopped' && _status === null&&!isRecording && !isReply ? 'block' : 'none'}}/>
|
|
<SentimentSatisfiedAltIcon onClick={handleOpenEmoji}
|
|
<SentimentSatisfiedAltIcon onClick={handleOpenEmoji}
|
|
fontSize='medium' sx={{color: isOpenEmoji ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
fontSize='medium' sx={{color: isOpenEmoji ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
- pointerEvents: file || type === 'recording' || type === 'filming' ? 'none' : "auto",
|
|
|
|
|
|
+ pointerEvents: file || status || _status ? 'none' : "auto",
|
|
'&:hover': { color: 'rgb(41, 139, 231)' }, marginRight:1}}/>
|
|
'&:hover': { color: 'rgb(41, 139, 231)' }, marginRight:1}}/>
|
|
<CommentIcon onClick={handleOpenCaption}
|
|
<CommentIcon onClick={handleOpenCaption}
|
|
fontSize='medium' sx={{color: isOpenCaption || caption ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
fontSize='medium' sx={{color: isOpenCaption || caption ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
- pointerEvents: value || file || type === 'recording' || type === 'filming'? 'auto' : "none",
|
|
|
|
|
|
+ pointerEvents: value || file || status === 'stopped' || _status === 'stopped'? 'auto' : "none",
|
|
'&:hover': { color: 'rgb(41, 139, 231)'}}} />
|
|
'&:hover': { color: 'rgb(41, 139, 231)'}}} />
|
|
<div onClick={handleCloseEmoji} className={classes.overlay} id='overlay'
|
|
<div onClick={handleCloseEmoji} className={classes.overlay} id='overlay'
|
|
style={{ display: isOpenEmoji ? 'block':'none'}}>
|
|
style={{ display: isOpenEmoji ? 'block':'none'}}>
|
|
@@ -586,18 +608,18 @@ const SendMessage = ({isArrow,silentMode,isReply,setIsReply,handleScrollToTheMes
|
|
</div>
|
|
</div>
|
|
<textarea disabled={file || type === 'recording' || type === 'filming' ? true : false} value={value} onBlur={handleBlurTextarea}
|
|
<textarea disabled={file || type === 'recording' || type === 'filming' ? true : false} value={value} onBlur={handleBlurTextarea}
|
|
onFocus={handleFocusTextarea} onChange={handleTextarea} className={classes.textarea}
|
|
onFocus={handleFocusTextarea} onChange={handleTextarea} className={classes.textarea}
|
|
- placeholder={file ? 'The File is ready to send' : status === 'idle' && _status === 'idle' ? 'Message' :
|
|
|
|
|
|
+ placeholder={file ? 'The File is ready to send' : status === null && _status === null ? 'Message' :
|
|
`${status === 'stopped' || _status === 'stopped' ? type === 'recording' || type === 'filming'?'Recorded':'Message':'Recording in progress...'}`} rows={1}
|
|
`${status === 'stopped' || _status === 'stopped' ? type === 'recording' || type === 'filming'?'Recorded':'Message':'Recording in progress...'}`} rows={1}
|
|
style={{color:value || file || type === 'recording' || type === 'filming' ?'rgb(41, 139, 231)':'#6b6b6b'}}>
|
|
style={{color:value || file || type === 'recording' || type === 'filming' ?'rgb(41, 139, 231)':'#6b6b6b'}}>
|
|
</textarea>
|
|
</textarea>
|
|
<PhotoCameraFrontIcon onClick={handleOpenCamera} fontSize='medium'
|
|
<PhotoCameraFrontIcon onClick={handleOpenCamera} fontSize='medium'
|
|
sx={{color: isOpenCamera || type === 'base64' ? 'rgb(62, 149, 231)' : '#6b6b6b', marginRight: 1, cursor: 'pointer',
|
|
sx={{color: isOpenCamera || type === 'base64' ? 'rgb(62, 149, 231)' : '#6b6b6b', marginRight: 1, cursor: 'pointer',
|
|
- pointerEvents: type === 'content' || type === 'application' || value || status !== 'idle'
|
|
|
|
- || _status !== 'idle' || isReply ? 'none' : "auto",
|
|
|
|
|
|
+ pointerEvents: type === 'content' || type === 'application' || value || status !== null
|
|
|
|
+ || _status !== null || isReply ? 'none' : "auto",
|
|
'&:hover': { color: 'rgb(41, 139, 231)'}}}/>
|
|
'&:hover': { color: 'rgb(41, 139, 231)'}}}/>
|
|
<AttachFileIcon onClick={handleOpenFileMenu} className={classes.attachIcon}
|
|
<AttachFileIcon onClick={handleOpenFileMenu} className={classes.attachIcon}
|
|
fontSize='medium' sx={{color: isOpenMenu || type === 'content' || type === 'application' ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
fontSize='medium' sx={{color: isOpenMenu || type === 'content' || type === 'application' ? 'rgb(41, 139, 231)' : '#6b6b6b', cursor: 'pointer',
|
|
- pointerEvents: type === 'base64' || value || status !== 'idle' || _status !== 'idle' || isReply ? 'none' : "auto", '&:hover':
|
|
|
|
|
|
+ pointerEvents: type === 'base64' || value || status !== null || _status !== null || isReply ? 'none' : "auto", '&:hover':
|
|
{ color: 'rgb(41, 139, 231)'}}}/>
|
|
{ color: 'rgb(41, 139, 231)'}}}/>
|
|
<div onClick={handleCloseFileMenu} className={classes.overlay} id='overlay'
|
|
<div onClick={handleCloseFileMenu} className={classes.overlay} id='overlay'
|
|
style={{ display: isOpenMenu ? 'block':'none'}}>
|
|
style={{ display: isOpenMenu ? 'block':'none'}}>
|