您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hooks.native.ts 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { useSelector } from 'react-redux';
  2. import ChatButton from '../chat/components/native/ChatButton';
  3. import RaiseHandContainerButtons from '../reactions/components/native/RaiseHandContainerButtons';
  4. import TileViewButton from '../video-layout/components/TileViewButton';
  5. import { iAmVisitor } from '../visitors/functions';
  6. import AudioMuteButton from './components/native/AudioMuteButton';
  7. import CustomOptionButton from './components/native/CustomOptionButton';
  8. import HangupContainerButtons from './components/native/HangupContainerButtons';
  9. import OverflowMenuButton from './components/native/OverflowMenuButton';
  10. import ScreenSharingButton from './components/native/ScreenSharingButton';
  11. import VideoMuteButton from './components/native/VideoMuteButton';
  12. import { isDesktopShareButtonDisabled } from './functions.native';
  13. import { ICustomToolbarButton, IToolboxNativeButton, NativeToolbarButton } from './types';
  14. const microphone = {
  15. key: 'microphone',
  16. Content: AudioMuteButton,
  17. group: 0
  18. };
  19. const camera = {
  20. key: 'camera',
  21. Content: VideoMuteButton,
  22. group: 0
  23. };
  24. const chat = {
  25. key: 'chat',
  26. Content: ChatButton,
  27. group: 1
  28. };
  29. const screensharing = {
  30. key: 'screensharing',
  31. Content: ScreenSharingButton,
  32. group: 1
  33. };
  34. const raisehand = {
  35. key: 'raisehand',
  36. Content: RaiseHandContainerButtons,
  37. group: 2
  38. };
  39. const tileview = {
  40. key: 'tileview',
  41. Content: TileViewButton,
  42. group: 2
  43. };
  44. const overflowmenu = {
  45. key: 'overflowmenu',
  46. Content: OverflowMenuButton,
  47. group: 3
  48. };
  49. const hangup = {
  50. key: 'hangup',
  51. Content: HangupContainerButtons,
  52. group: 3
  53. };
  54. /**
  55. * A hook that returns the audio mute button.
  56. *
  57. * @returns {Object | undefined}
  58. */
  59. function getAudioMuteButton() {
  60. const _iAmVisitor = useSelector(iAmVisitor);
  61. if (!_iAmVisitor) {
  62. return microphone;
  63. }
  64. }
  65. /**
  66. * A hook that returns the video mute button.
  67. *
  68. * @returns {Object | undefined}
  69. */
  70. function getVideoMuteButton() {
  71. const _iAmVisitor = useSelector(iAmVisitor);
  72. if (!_iAmVisitor) {
  73. return camera;
  74. }
  75. }
  76. /**
  77. * A hook that returns the chat button.
  78. *
  79. * @returns {Object | undefined}
  80. */
  81. function getChatButton() {
  82. const _iAmVisitor = useSelector(iAmVisitor);
  83. if (!_iAmVisitor) {
  84. return chat;
  85. }
  86. }
  87. /**
  88. * A hook that returns the screen sharing button.
  89. *
  90. * @returns {Object | undefined}
  91. */
  92. function getScreenSharingButton() {
  93. const _iAmVisitor = useSelector(iAmVisitor);
  94. const _isScreenShareButtonDisabled = useSelector(isDesktopShareButtonDisabled);
  95. if (!_isScreenShareButtonDisabled && !_iAmVisitor) {
  96. return screensharing;
  97. }
  98. }
  99. /**
  100. * A hook that returns the tile view button.
  101. *
  102. * @returns {Object | undefined}
  103. */
  104. function getTileViewButton() {
  105. const _iAmVisitor = useSelector(iAmVisitor);
  106. if (!_iAmVisitor) {
  107. return tileview;
  108. }
  109. }
  110. /**
  111. * A hook that returns the overflow menu button.
  112. *
  113. * @returns {Object | undefined}
  114. */
  115. function getOverflowMenuButton() {
  116. const _iAmVisitor = useSelector(iAmVisitor);
  117. if (!_iAmVisitor) {
  118. return overflowmenu;
  119. }
  120. }
  121. /**
  122. * Returns all buttons that could be rendered.
  123. *
  124. * @param {Object} _customToolbarButtons - An array containing custom buttons objects.
  125. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
  126. */
  127. export function useNativeToolboxButtons(
  128. _customToolbarButtons?: ICustomToolbarButton[]): { [key: string]: IToolboxNativeButton; } {
  129. const audioMuteButton = getAudioMuteButton();
  130. const videoMuteButton = getVideoMuteButton();
  131. const chatButton = getChatButton();
  132. const screenSharingButton = getScreenSharingButton();
  133. const tileViewButton = getTileViewButton();
  134. const overflowMenuButton = getOverflowMenuButton();
  135. const buttons: { [key in NativeToolbarButton]?: IToolboxNativeButton; } = {
  136. microphone: audioMuteButton,
  137. camera: videoMuteButton,
  138. chat: chatButton,
  139. screensharing: screenSharingButton,
  140. raisehand,
  141. tileview: tileViewButton,
  142. overflowmenu: overflowMenuButton,
  143. hangup
  144. };
  145. const buttonKeys = Object.keys(buttons) as NativeToolbarButton[];
  146. buttonKeys.forEach(
  147. key => typeof buttons[key] === 'undefined' && delete buttons[key]);
  148. const customButtons = _customToolbarButtons?.reduce((prev, { backgroundColor, icon, id, text }) => {
  149. prev[id] = {
  150. backgroundColor,
  151. key: id,
  152. id,
  153. Content: CustomOptionButton,
  154. group: 4,
  155. icon,
  156. text
  157. };
  158. return prev;
  159. }, {} as { [key: string]: ICustomToolbarButton; });
  160. return {
  161. ...buttons,
  162. ...customButtons
  163. };
  164. }