index.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import { makeStyles, Typography } from '@material-ui/core'
  2. import { useState } from 'react';
  3. import { useSelector } from 'react-redux';
  4. import ListItemText from '@mui/material/ListItemText';
  5. import ListItemAvatar from '@mui/material/ListItemAvatar';
  6. import Avatar from '@mui/material/Avatar';
  7. import MinimizeIcon from '@mui/icons-material/Minimize';
  8. import CropLandscapeIcon from '@mui/icons-material/CropLandscape';
  9. import CloseIcon from '@mui/icons-material/Close';
  10. import ScreenShareIcon from '@mui/icons-material/ScreenShare';
  11. import StopScreenShareIcon from '@mui/icons-material/StopScreenShare';
  12. import VideocamIcon from '@mui/icons-material/Videocam';
  13. import VideocamOffIcon from '@mui/icons-material/VideocamOff';
  14. import MicIcon from '@mui/icons-material/Mic';
  15. import MicOffIcon from '@mui/icons-material/MicOff';
  16. import CallEndIcon from '@mui/icons-material/CallEnd';
  17. import Moveable from "react-moveable";
  18. import {OnDrag,OnResize,OnScale} from "react-moveable";
  19. import { getChat } from '../../../../../../redux/chat/selector';
  20. import { prodAwsS3,firstLetter,slicedWord } from '../../../../../../helpers'
  21. const useStyles = makeStyles({
  22. overlay: {
  23. position: 'fixed',
  24. top: 0,
  25. left: 0,
  26. width: '100vw',
  27. height: '100vh',
  28. zIndex: 100,
  29. overflowY: 'hidden',
  30. },
  31. shareScreenActive: {
  32. width: '90%',
  33. borderRadius: 7,
  34. margin: 'auto',
  35. border:'solid 2px #0084ff',
  36. },
  37. shareScreenDisabled: {
  38. width: 0,
  39. height:0,
  40. },
  41. modalCall: {
  42. background: 'rgb(36, 36, 36)',
  43. position: 'absolute',
  44. display: 'flex',
  45. flexDirection: 'column',
  46. justifyContent: 'start',
  47. alignItems: 'center',
  48. justifyItems:"center",
  49. width: '34vw',
  50. height:'50vh',
  51. left: '33vw',
  52. bottom: '25vh',
  53. borderRadius: 7,
  54. },
  55. rightIcons: {
  56. display: 'flex',
  57. justifyContent: 'end',
  58. alignContent: 'center',
  59. alignItems: 'center',
  60. width:'100%'
  61. },
  62. rightIconWrapper: {
  63. color: '#ffffff',
  64. cursor: 'pointer',
  65. padding:'3px 10px 3px 10px',
  66. '&:hover': {
  67. backgroundColor:'rgb(80, 80, 80)'
  68. }
  69. },
  70. rightIconWrapperClose: {
  71. color: '#ffffff',
  72. cursor: 'pointer',
  73. padding:'3px 10px 3px 10px',
  74. borderTopRightRadius:7,
  75. '&:hover': {
  76. backgroundColor:'#f02a2a'
  77. }
  78. },
  79. statusCall: {
  80. color: "#dfdfdf",
  81. animation: 'ripple 4s infinite ease-in-out',
  82. },
  83. animatedDots: {
  84. fontWeight: 'bold',
  85. display:'inline-block',
  86. fontFamily: 'monospace',
  87. clipPath: 'inset(0 3ch 0 0)',
  88. animation: `$run 2s steps(5) infinite`,
  89. },
  90. bottomWrapper: {
  91. display: 'flex',
  92. justifyContent: 'center',
  93. padding: 5
  94. },
  95. bottomItem: {
  96. display: 'flex',
  97. flexDirection: 'column',
  98. justifyContent: 'center',
  99. alignContent: 'center',
  100. alignItems: 'center',
  101. cursor:'pointer',
  102. width: 80,
  103. },
  104. bottomIcon: {
  105. cursor:'pointer',
  106. },
  107. titleIconBottom: {
  108. color: '#ffffff',
  109. fontSize: 13,
  110. paddingTop:7
  111. },
  112. '@keyframes run': {
  113. to: {
  114. clipPath: 'inset(0 -1ch 0 0)'
  115. },
  116. },
  117. })
  118. interface ICallModal {
  119. setModalCall:any,
  120. shareRef: any,
  121. videoRef: any,
  122. }
  123. const CallModal = ({setModalCall,shareRef,videoRef}:ICallModal) => {
  124. const classes = useStyles()
  125. const { name, lastName, avatarUrl, color } = useSelector(getChat)
  126. const [mute, setMute] = useState<boolean>(false)
  127. const [share, setShare] = useState<any>(null)
  128. const target = videoRef.current
  129. const handleShareScreen = async () => {
  130. const displayMediaStreamConstraints = {
  131. video: true
  132. };
  133. const navigator:any = window.navigator
  134. const stream = await navigator.mediaDevices.getDisplayMedia(displayMediaStreamConstraints);
  135. shareRef.current.srcObject = stream;
  136. setShare(true)
  137. stream.getVideoTracks()[0].onended = () => setShare(false)
  138. };
  139. const handleMute = () => setMute(prevState => !prevState)
  140. const handleCloseCallModal = () => setModalCall(false)
  141. // requesting, waiting ,ringing, hanging up,line busy
  142. return (
  143. <div className={classes.overlay} >
  144. <video ref={videoRef} style={{minWidth:100,minHeight:70}} playsInline muted autoPlay/>
  145. <Moveable
  146. target={target}
  147. container={null}
  148. origin={true}
  149. edge={false}
  150. draggable={true}
  151. throttleDrag={0}
  152. onDrag={({ target, transform }: OnDrag) =>
  153. target!.style.transform = transform }
  154. keepRatio={true}
  155. resizable={true}
  156. throttleResize={0}
  157. onResize={({target, width, height,delta}: OnResize) => {
  158. delta[0] && (target!.style.width = `${width}px`);
  159. delta[1] && (target!.style.height = `${height}px`);
  160. }}
  161. scalable={true}
  162. throttleScale={0}
  163. onScale={({target, scale, transform}: OnScale) => {
  164. target!.style.transform = transform;
  165. }}
  166. rotatable={false}
  167. pinchable={true}
  168. />
  169. <div className={classes.modalCall}>
  170. <div className={classes.rightIcons} style={{marginBottom: share?0:40,}}>
  171. <div className={classes.rightIconWrapper}>
  172. <MinimizeIcon fontSize='small' />
  173. </div>
  174. <div className={classes.rightIconWrapper}>
  175. <CropLandscapeIcon fontSize='small' />
  176. </div>
  177. <div className={classes.rightIconWrapperClose} onClick={handleCloseCallModal}>
  178. <CloseIcon fontSize='small' />
  179. </div>
  180. </div>
  181. {!share&&<ListItemAvatar style={{marginBottom:15}}>
  182. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  183. sx={{ background: color, width: 120, height: 120, marginRight: 2, fontSize:30}}>
  184. {`${firstLetter(name)}${firstLetter(lastName)}`}
  185. </Avatar>
  186. </ListItemAvatar>}
  187. {!share&&<div style={{marginBottom:'auto'}}>
  188. <ListItemText primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
  189. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  190. primaryTypographyProps={{ color: '#ffffff', fontSize: 20, fontWeight: 500 }} />
  191. <ListItemText secondary={<span className={classes.statusCall}>
  192. ringing<span className={classes.animatedDots}>
  193. ...</span>
  194. </span>} secondaryTypographyProps={{ textAlign: "center" }} />
  195. </div>}
  196. <video className={share?classes.shareScreenActive:classes.shareScreenDisabled} ref={shareRef} playsInline muted autoPlay/>
  197. <div className={classes.bottomWrapper}>
  198. {!share&&<div className={classes.bottomItem}>
  199. <Avatar className={classes.bottomIcon} onClick={handleShareScreen}
  200. sx={{backgroundColor: '#ffffff',color: 'rgb(36, 36, 36)', width: 44, height: 44}}>
  201. <ScreenShareIcon fontSize="medium" />
  202. </Avatar>
  203. <Typography variant="h6" className={classes.titleIconBottom}>Screencast</Typography>
  204. </div>}
  205. <div className={classes.bottomItem}>
  206. <Avatar className={classes.bottomIcon}
  207. sx={{backgroundColor: share?'rgb(88, 88, 88)':'#ffffff',color: share?'#ffffff':'rgb(36, 36, 36)', width: 44, height: 44}}>
  208. <VideocamOffIcon fontSize="medium" />
  209. </Avatar>
  210. <Typography variant="h6" className={classes.titleIconBottom}>Start Video</Typography>
  211. </div>
  212. <div className={classes.bottomItem}>
  213. <Avatar className={classes.bottomIcon}
  214. sx={{backgroundColor: '#f02a2a',color: '#ffffff', width: 44, height: 44}}>
  215. <CallEndIcon fontSize="medium" />
  216. </Avatar>
  217. <Typography variant="h6" className={classes.titleIconBottom}>End Call</Typography>
  218. </div>
  219. <div className={classes.bottomItem}>
  220. <Avatar className={classes.bottomIcon} onClick={handleMute}
  221. sx={{backgroundColor: mute?'#ffffff':'rgb(88, 88, 88)',color: mute?'rgb(36, 36, 36)':'#ffffff', width: 44, height: 44}}>
  222. {mute?<MicOffIcon fontSize="medium" />:<MicIcon fontSize="medium" />}
  223. </Avatar>
  224. <Typography variant="h6" className={classes.titleIconBottom}>{mute?'Unmute':'Mute'}</Typography>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. )
  230. }
  231. export default CallModal