WebConference.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React from "react";
  2. import styled from "styled-components";
  3. import { getConfToken } from "../utils/api";
  4. import useLocalStorage from "../hooks/useLocalStorage";
  5. import { OpenViduProvider, StreamList } from "./react-useOpenVidu";
  6. const StyledWebConference = styled.div`
  7. position: fixed;
  8. top: 5em;
  9. right: 1em;
  10. line-height: 1em;
  11. bottom: 5.5em;
  12. z-index: 1;
  13. width: ${({ audioOnly }) => (audioOnly ? 80 : 150)}px;
  14. overflow-y: auto;
  15. overflow-x: hidden;
  16. padding: 0.5em;
  17. .stream-list {
  18. display: flex;
  19. flex-direction: column;
  20. gap: 5px;
  21. }
  22. & .local-stream {
  23. position: relative;
  24. & .actions {
  25. position: absolute;
  26. bottom: 2px;
  27. right: 0;
  28. left: 0;
  29. display: flex;
  30. justify-content: center;
  31. }
  32. & button {
  33. padding: 0;
  34. margin: 0;
  35. background-color: transparent;
  36. width: 30px;
  37. height: 30px;
  38. }
  39. }
  40. & .remote-stream {
  41. position: relative;
  42. }
  43. & .user-stream {
  44. position: relative;
  45. border: 1px solid #333;
  46. & .name {
  47. line-height: 1.6em;
  48. display: block;
  49. white-space: nowrap;
  50. overflow: hidden;
  51. text-overflow: ellipsis;
  52. width: 100%;
  53. padding: 1px 2px;
  54. background-color: #95959540;
  55. text-align: center;
  56. }
  57. & .mic {
  58. position: absolute;
  59. top: 2px;
  60. right: 2px;
  61. width: 30px;
  62. height: 30px;
  63. padding: 7px;
  64. & img {
  65. max-height: 100%;
  66. }
  67. }
  68. }
  69. `;
  70. const WebConference = ({ room, currentUser, users, enableVideo = false }) => {
  71. const getUserData = React.useCallback(
  72. () => JSON.stringify({ uid: currentUser.uid }),
  73. [currentUser.uid]
  74. );
  75. const [showLocalVideo, setShowLocalVideo] = useLocalStorage(
  76. "wcEnableLocalVideo",
  77. false
  78. );
  79. const [showLocalAudio, setShowLocalAudio] = useLocalStorage(
  80. "wcEnableLocalAudio",
  81. true
  82. );
  83. return (
  84. <OpenViduProvider
  85. room={room}
  86. parseUserData={JSON.parse}
  87. getUserData={getUserData}
  88. getToken={getConfToken}
  89. >
  90. <StyledWebConference audioOnly={true}>
  91. <StreamList
  92. currentUser={currentUser}
  93. users={users}
  94. audioOnly={!enableVideo}
  95. setLocalAudio={setShowLocalAudio}
  96. setLocalVideo={setShowLocalVideo}
  97. enableLocalVideo={showLocalVideo}
  98. enableLocalAudio={showLocalAudio}
  99. />
  100. </StyledWebConference>
  101. </OpenViduProvider>
  102. );
  103. };
  104. export default WebConference;