index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import Grid from '@mui/material/Grid'
  2. import { makeStyles } from '@material-ui/core'
  3. import { useSelector } from 'react-redux'
  4. import { useState,useRef } from 'react'
  5. import io from 'socket.io-client';
  6. import Moveable from "react-moveable";
  7. import { OnDrag } from "react-moveable";
  8. import LeftBar from './LeftBar'
  9. import CentralBar from './CentralBar'
  10. import RightBar from './RightBar'
  11. import CallBar from './CallBar';
  12. import { getRightIsOpen } from '../../redux/control/selector'
  13. import { getChatMemo } from '../../redux/chat/selector'
  14. import { getNightMode } from '../../redux/authorization/selector'
  15. import wallpaper from '../../img/wallpaper.jpg'
  16. import wallpaperNight from '../../img/wallpaperNight.jpg'
  17. import { prodSocketURL } from '../../helpers';
  18. const socket = io(prodSocketURL)
  19. const useStyles = makeStyles({
  20. container: {
  21. minHeight: '100vh',
  22. maxHeight: '100vh',
  23. },
  24. centralAndRight: {
  25. display:'flex'
  26. },
  27. myVideo: {
  28. width: 250,
  29. height: 'auto',
  30. cursor: 'pointer',
  31. position: 'absolute',
  32. top: 0,
  33. left: 0,
  34. zIndex: 150,
  35. backgroundColor:'#28e217',
  36. },
  37. })
  38. const HomePage = () => {
  39. const classes = useStyles()
  40. const rightIsOpen = useSelector(getRightIsOpen)
  41. const myVideoRef = useRef<any | null>(null);
  42. const chatDivRef = useRef<any | null>(null)
  43. const nightMode = useSelector(getNightMode)
  44. const { companionId } = useSelector(getChatMemo)
  45. const [callStatus,setCallStatus] = useState<string>('')
  46. const backgroundImage = `url(${nightMode ? wallpaperNight : wallpaper})`
  47. const handleStartCall = () => setCallStatus('requesting')
  48. return (
  49. <Grid className={classes.container} container spacing={0} >
  50. <video className={classes.myVideo} ref={myVideoRef} playsInline autoPlay muted/>
  51. <Moveable
  52. target={myVideoRef.current}
  53. draggable={true}
  54. throttleDrag={0}
  55. hideDefaultLines={true}
  56. renderDirections={[]}
  57. rotationPosition="none"
  58. origin={false}
  59. onDrag={({ target, transform }: OnDrag) =>
  60. target!.style.transform = transform }
  61. />
  62. <CallBar callStatus={callStatus} setCallStatus={setCallStatus} socket={socket} myVideoRef={myVideoRef}/>
  63. <LeftBar chatDivRef={chatDivRef} />
  64. {companionId ?
  65. <Grid item lg={9} className={classes.centralAndRight}>
  66. <CentralBar rightIsOpen={rightIsOpen} chatDivRef={chatDivRef}
  67. companionId={companionId} backgroundImage={backgroundImage}
  68. handleStartCall={handleStartCall}/>
  69. <RightBar rightIsOpen={rightIsOpen} chatDivRef={chatDivRef} />
  70. </Grid> :
  71. <Grid item lg={9} style={{backgroundImage}}/>}
  72. </Grid>
  73. )
  74. }
  75. export default HomePage