You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.web.ts 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. import { IReduxState } from '../app/types';
  2. import { getToolbarButtons } from '../base/config/functions.web';
  3. import { hasAvailableDevices } from '../base/devices/functions';
  4. import { MEET_FEATURES } from '../base/jwt/constants';
  5. import { isJwtFeatureEnabled } from '../base/jwt/functions';
  6. import { IGUMPendingState } from '../base/media/types';
  7. import ChatButton from '../chat/components/web/ChatButton';
  8. import EmbedMeetingButton from '../embed-meeting/components/EmbedMeetingButton';
  9. import SharedDocumentButton from '../etherpad/components/SharedDocumentButton.web';
  10. import FeedbackButton from '../feedback/components/FeedbackButton.web';
  11. import InviteButton from '../invite/components/add-people-dialog/web/InviteButton';
  12. import KeyboardShortcutsButton from '../keyboard-shortcuts/components/web/KeyboardShortcutsButton';
  13. import NoiseSuppressionButton from '../noise-suppression/components/NoiseSuppressionButton';
  14. import ParticipantsPaneButton from '../participants-pane/components/web/ParticipantsPaneButton';
  15. import RaiseHandContainerButton from '../reactions/components/web/RaiseHandContainerButtons';
  16. import ReactionsMenuButton from '../reactions/components/web/ReactionsMenuButton';
  17. import LiveStreamButton from '../recording/components/LiveStream/web/LiveStreamButton';
  18. import RecordButton from '../recording/components/Recording/web/RecordButton';
  19. import ShareAudioButton from '../screen-share/components/web/ShareAudioButton';
  20. import { isScreenMediaShared } from '../screen-share/functions';
  21. import SecurityDialogButton from '../security/components/security-dialog/web/SecurityDialogButton';
  22. import SettingsButton from '../settings/components/web/SettingsButton';
  23. import SharedVideoButton from '../shared-video/components/web/SharedVideoButton';
  24. import SpeakerStatsButton from '../speaker-stats/components/web/SpeakerStatsButton';
  25. import ClosedCaptionButton from '../subtitles/components/web/ClosedCaptionButton';
  26. import TileViewButton from '../video-layout/components/TileViewButton';
  27. import VideoQualityButton from '../video-quality/components/VideoQualityButton.web';
  28. import VideoBackgroundButton from '../virtual-background/components/VideoBackgroundButton';
  29. import WhiteboardButton from '../whiteboard/components/web/WhiteboardButton';
  30. import { isWhiteboardVisible } from '../whiteboard/functions';
  31. import DownloadButton from './components/DownloadButton';
  32. import HelpButton from './components/HelpButton';
  33. import AudioSettingsButton from './components/web/AudioSettingsButton';
  34. import CustomOptionButton from './components/web/CustomOptionButton';
  35. import FullscreenButton from './components/web/FullscreenButton';
  36. import LinkToSalesforceButton from './components/web/LinkToSalesforceButton';
  37. import ProfileButton from './components/web/ProfileButton';
  38. import ShareDesktopButton from './components/web/ShareDesktopButton';
  39. import ToggleCameraButton from './components/web/ToggleCameraButton';
  40. import VideoSettingsButton from './components/web/VideoSettingsButton';
  41. import { TOOLBAR_TIMEOUT } from './constants';
  42. import { IToolboxButton } from './types';
  43. export * from './functions.any';
  44. /**
  45. * Helper for getting the height of the toolbox.
  46. *
  47. * @returns {number} The height of the toolbox.
  48. */
  49. export function getToolboxHeight() {
  50. const toolbox = document.getElementById('new-toolbox');
  51. return toolbox?.clientHeight || 0;
  52. }
  53. /**
  54. * Indicates if a toolbar button is enabled.
  55. *
  56. * @param {string} name - The name of the setting section as defined in
  57. * interface_config.js.
  58. * @param {IReduxState} state - The redux state.
  59. * @returns {boolean|undefined} - True to indicate that the given toolbar button
  60. * is enabled, false - otherwise.
  61. */
  62. export function isButtonEnabled(name: string, state: IReduxState) {
  63. const toolbarButtons = getToolbarButtons(state);
  64. return toolbarButtons.indexOf(name) !== -1;
  65. }
  66. /**
  67. * Indicates if the toolbox is visible or not.
  68. *
  69. * @param {IReduxState} state - The state from the Redux store.
  70. * @returns {boolean} - True to indicate that the toolbox is visible, false -
  71. * otherwise.
  72. */
  73. export function isToolboxVisible(state: IReduxState) {
  74. const { iAmRecorder, iAmSipGateway, toolbarConfig } = state['features/base/config'];
  75. const { alwaysVisible } = toolbarConfig || {};
  76. const {
  77. timeoutID,
  78. visible
  79. } = state['features/toolbox'];
  80. const { audioSettingsVisible, videoSettingsVisible } = state['features/settings'];
  81. const whiteboardVisible = isWhiteboardVisible(state);
  82. return Boolean(!iAmRecorder && !iAmSipGateway
  83. && (
  84. timeoutID
  85. || visible
  86. || alwaysVisible
  87. || audioSettingsVisible
  88. || videoSettingsVisible
  89. || whiteboardVisible
  90. ));
  91. }
  92. /**
  93. * Indicates if the audio settings button is disabled or not.
  94. *
  95. * @param {IReduxState} state - The state from the Redux store.
  96. * @returns {boolean}
  97. */
  98. export function isAudioSettingsButtonDisabled(state: IReduxState) {
  99. return !(hasAvailableDevices(state, 'audioInput')
  100. || hasAvailableDevices(state, 'audioOutput'))
  101. || state['features/base/config'].startSilent;
  102. }
  103. /**
  104. * Indicates if the desktop share button is disabled or not.
  105. *
  106. * @param {IReduxState} state - The state from the Redux store.
  107. * @returns {boolean}
  108. */
  109. export function isDesktopShareButtonDisabled(state: IReduxState) {
  110. const { muted, unmuteBlocked } = state['features/base/media'].video;
  111. const videoOrShareInProgress = !muted || isScreenMediaShared(state);
  112. const enabledInJwt = isJwtFeatureEnabled(state, MEET_FEATURES.SCREEN_SHARING, true, true);
  113. return !enabledInJwt || (unmuteBlocked && !videoOrShareInProgress);
  114. }
  115. /**
  116. * Indicates if the video settings button is disabled or not.
  117. *
  118. * @param {IReduxState} state - The state from the Redux store.
  119. * @returns {boolean}
  120. */
  121. export function isVideoSettingsButtonDisabled(state: IReduxState) {
  122. return !hasAvailableDevices(state, 'videoInput');
  123. }
  124. /**
  125. * Indicates if the video mute button is disabled or not.
  126. *
  127. * @param {IReduxState} state - The state from the Redux store.
  128. * @returns {boolean}
  129. */
  130. export function isVideoMuteButtonDisabled(state: IReduxState) {
  131. const { muted, unmuteBlocked, gumPending } = state['features/base/media'].video;
  132. return !hasAvailableDevices(state, 'videoInput')
  133. || (unmuteBlocked && Boolean(muted))
  134. || gumPending !== IGUMPendingState.NONE;
  135. }
  136. /**
  137. * If an overflow drawer should be displayed or not.
  138. * This is usually done for mobile devices or on narrow screens.
  139. *
  140. * @param {IReduxState} state - The state from the Redux store.
  141. * @returns {boolean}
  142. */
  143. export function showOverflowDrawer(state: IReduxState) {
  144. return state['features/toolbox'].overflowDrawer;
  145. }
  146. /**
  147. * Returns true if the overflow menu button is displayed and false otherwise.
  148. *
  149. * @param {IReduxState} state - The state from the Redux store.
  150. * @returns {boolean} - True if the overflow menu button is displayed and false otherwise.
  151. */
  152. export function showOverflowMenu(state: IReduxState) {
  153. return state['features/toolbox'].overflowMenuVisible;
  154. }
  155. /**
  156. * Indicates whether the toolbox is enabled or not.
  157. *
  158. * @param {IReduxState} state - The state from the Redux store.
  159. * @returns {boolean}
  160. */
  161. export function isToolboxEnabled(state: IReduxState) {
  162. return state['features/toolbox'].enabled;
  163. }
  164. /**
  165. * Returns the toolbar timeout from config or the default value.
  166. *
  167. * @param {IReduxState} state - The state from the Redux store.
  168. * @returns {number} - Toolbar timeout in milliseconds.
  169. */
  170. export function getToolbarTimeout(state: IReduxState) {
  171. const { toolbarConfig } = state['features/base/config'];
  172. return toolbarConfig?.timeout || TOOLBAR_TIMEOUT;
  173. }
  174. /**
  175. * Returns all buttons that could be rendered.
  176. *
  177. * @param {Object} _customToolbarButtons - An array containing custom buttons objects.
  178. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
  179. */
  180. export function getAllToolboxButtons(_customToolbarButtons?: {
  181. icon: string;
  182. id: string;
  183. text: string;
  184. }[]): { [key: string]: IToolboxButton; } {
  185. const microphone = {
  186. key: 'microphone',
  187. Content: AudioSettingsButton,
  188. group: 0
  189. };
  190. const camera = {
  191. key: 'camera',
  192. Content: VideoSettingsButton,
  193. group: 0
  194. };
  195. const profile = {
  196. key: 'profile',
  197. Content: ProfileButton,
  198. group: 1
  199. };
  200. const chat = {
  201. key: 'chat',
  202. Content: ChatButton,
  203. group: 2
  204. };
  205. const desktop = {
  206. key: 'desktop',
  207. Content: ShareDesktopButton,
  208. group: 2
  209. };
  210. // In Narrow layout and mobile web we are using drawer for popups and that is why it is better to include
  211. // all forms of reactions in the overflow menu. Otherwise the toolbox will be hidden and the reactions popup
  212. // misaligned.
  213. const raisehand = {
  214. key: 'raisehand',
  215. Content: RaiseHandContainerButton,
  216. group: 2
  217. };
  218. const reactions = {
  219. key: 'reactions',
  220. Content: ReactionsMenuButton,
  221. group: 2
  222. };
  223. const participants = {
  224. key: 'participants-pane',
  225. Content: ParticipantsPaneButton,
  226. group: 2
  227. };
  228. const invite = {
  229. key: 'invite',
  230. Content: InviteButton,
  231. group: 2
  232. };
  233. const tileview = {
  234. key: 'tileview',
  235. Content: TileViewButton,
  236. group: 2
  237. };
  238. const toggleCamera = {
  239. key: 'toggle-camera',
  240. Content: ToggleCameraButton,
  241. group: 2
  242. };
  243. const videoQuality = {
  244. key: 'videoquality',
  245. Content: VideoQualityButton,
  246. group: 2
  247. };
  248. const fullscreen = {
  249. key: 'fullscreen',
  250. Content: FullscreenButton,
  251. group: 2
  252. };
  253. const security = {
  254. key: 'security',
  255. alias: 'info',
  256. Content: SecurityDialogButton,
  257. group: 2
  258. };
  259. const cc = {
  260. key: 'closedcaptions',
  261. Content: ClosedCaptionButton,
  262. group: 2
  263. };
  264. const recording = {
  265. key: 'recording',
  266. Content: RecordButton,
  267. group: 2
  268. };
  269. const livestreaming = {
  270. key: 'livestreaming',
  271. Content: LiveStreamButton,
  272. group: 2
  273. };
  274. const linkToSalesforce = {
  275. key: 'linktosalesforce',
  276. Content: LinkToSalesforceButton,
  277. group: 2
  278. };
  279. const shareVideo = {
  280. key: 'sharedvideo',
  281. Content: SharedVideoButton,
  282. group: 3
  283. };
  284. const shareAudio = {
  285. key: 'shareaudio',
  286. Content: ShareAudioButton,
  287. group: 3
  288. };
  289. const noiseSuppression = {
  290. key: 'noisesuppression',
  291. Content: NoiseSuppressionButton,
  292. group: 3
  293. };
  294. const whiteboard = {
  295. key: 'whiteboard',
  296. Content: WhiteboardButton,
  297. group: 3
  298. };
  299. const etherpad = {
  300. key: 'etherpad',
  301. Content: SharedDocumentButton,
  302. group: 3
  303. };
  304. const virtualBackground = {
  305. key: 'select-background',
  306. Content: VideoBackgroundButton,
  307. group: 3
  308. };
  309. const speakerStats = {
  310. key: 'stats',
  311. Content: SpeakerStatsButton,
  312. group: 3
  313. };
  314. const settings = {
  315. key: 'settings',
  316. Content: SettingsButton,
  317. group: 4
  318. };
  319. const shortcuts = {
  320. key: 'shortcuts',
  321. Content: KeyboardShortcutsButton,
  322. group: 4
  323. };
  324. const embed = {
  325. key: 'embedmeeting',
  326. Content: EmbedMeetingButton,
  327. group: 4
  328. };
  329. const feedback = {
  330. key: 'feedback',
  331. Content: FeedbackButton,
  332. group: 4
  333. };
  334. const download = {
  335. key: 'download',
  336. Content: DownloadButton,
  337. group: 4
  338. };
  339. const help = {
  340. key: 'help',
  341. Content: HelpButton,
  342. group: 4
  343. };
  344. const customButtons = _customToolbarButtons?.reduce((prev, { icon, id, text }) => {
  345. return {
  346. ...prev,
  347. [id]: {
  348. key: id,
  349. Content: CustomOptionButton,
  350. group: 4,
  351. icon,
  352. text
  353. }
  354. };
  355. }, {});
  356. return {
  357. microphone,
  358. camera,
  359. profile,
  360. desktop,
  361. chat,
  362. raisehand,
  363. reactions,
  364. participants,
  365. invite,
  366. tileview,
  367. toggleCamera,
  368. videoQuality,
  369. fullscreen,
  370. security,
  371. cc,
  372. recording,
  373. livestreaming,
  374. linkToSalesforce,
  375. shareVideo,
  376. shareAudio,
  377. noiseSuppression,
  378. whiteboard,
  379. etherpad,
  380. virtualBackground,
  381. speakerStats,
  382. settings,
  383. shortcuts,
  384. embed,
  385. feedback,
  386. download,
  387. help,
  388. ...customButtons
  389. };
  390. }