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 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import { IReduxState } from '../../app/types';
  2. import JitsiMeetJS from '../../base/lib-jitsi-meet';
  3. import { NOTIFY_CLICK_MODE } from '../../toolbox/constants';
  4. import {
  5. IConfig,
  6. IDeeplinkingConfig,
  7. IDeeplinkingMobileConfig,
  8. IDeeplinkingPlatformConfig,
  9. NotifyClickButton
  10. } from './configType';
  11. import { TOOLBAR_BUTTONS } from './constants';
  12. export * from './functions.any';
  13. /**
  14. * Removes all analytics related options from the given configuration, in case of a libre build.
  15. *
  16. * @param {*} _config - The configuration which needs to be cleaned up.
  17. * @returns {void}
  18. */
  19. export function _cleanupConfig(_config: IConfig) {
  20. return;
  21. }
  22. /**
  23. * Returns the replaceParticipant config.
  24. *
  25. * @param {Object} state - The state of the app.
  26. * @returns {boolean}
  27. */
  28. export function getReplaceParticipant(state: IReduxState): string | undefined {
  29. return state['features/base/config'].replaceParticipant;
  30. }
  31. /**
  32. * Returns the list of enabled toolbar buttons.
  33. *
  34. * @param {Object} state - The redux state.
  35. * @returns {Array<string>} - The list of enabled toolbar buttons.
  36. */
  37. export function getToolbarButtons(state: IReduxState): Array<string> {
  38. const { toolbarButtons, customToolbarButtons } = state['features/base/config'];
  39. const customButtons = customToolbarButtons?.map(({ id }) => id);
  40. const buttons = Array.isArray(toolbarButtons) ? toolbarButtons : TOOLBAR_BUTTONS;
  41. if (customButtons) {
  42. buttons.push(...customButtons);
  43. }
  44. return buttons;
  45. }
  46. /**
  47. * Returns the configuration value of web-hid feature.
  48. *
  49. * @param {Object} state - The state of the app.
  50. * @returns {boolean} True if web-hid feature should be enabled, otherwise false.
  51. */
  52. export function getWebHIDFeatureConfig(state: IReduxState): boolean {
  53. return state['features/base/config'].enableWebHIDFeature || false;
  54. }
  55. /**
  56. * Checks if the specified button is enabled.
  57. *
  58. * @param {string} buttonName - The name of the button.
  59. * {@link interfaceConfig}.
  60. * @param {Object|Array<string>} state - The redux state or the array with the enabled buttons.
  61. * @returns {boolean} - True if the button is enabled and false otherwise.
  62. */
  63. export function isToolbarButtonEnabled(buttonName: string, state: IReduxState | Array<string>) {
  64. const buttons = Array.isArray(state) ? state : getToolbarButtons(state);
  65. return buttons.includes(buttonName);
  66. }
  67. /**
  68. * Returns whether audio level measurement is enabled or not.
  69. *
  70. * @param {Object} state - The state of the app.
  71. * @returns {boolean}
  72. */
  73. export function areAudioLevelsEnabled(state: IReduxState): boolean {
  74. return !state['features/base/config'].disableAudioLevels && JitsiMeetJS.isCollectingLocalStats();
  75. }
  76. /**
  77. * Sets the defaults for deeplinking.
  78. *
  79. * @param {IDeeplinkingConfig} deeplinking - The deeplinking config.
  80. * @returns {void}
  81. */
  82. export function _setDeeplinkingDefaults(deeplinking: IDeeplinkingConfig) {
  83. const {
  84. desktop = {} as IDeeplinkingPlatformConfig,
  85. android = {} as IDeeplinkingMobileConfig,
  86. ios = {} as IDeeplinkingMobileConfig
  87. } = deeplinking;
  88. desktop.appName = desktop.appName || 'Jitsi Meet';
  89. ios.appName = ios.appName || 'Jitsi Meet';
  90. ios.appScheme = ios.appScheme || 'org.jitsi.meet';
  91. ios.downloadLink = ios.downloadLink
  92. || 'https://itunes.apple.com/us/app/jitsi-meet/id1165103905';
  93. if (ios.dynamicLink) {
  94. ios.dynamicLink.apn = ios.dynamicLink.apn || 'org.jitsi.meet';
  95. ios.dynamicLink.appCode = ios.dynamicLink.appCode || 'w2atb';
  96. ios.dynamicLink.ibi = ios.dynamicLink.ibi || 'com.atlassian.JitsiMeet.ios';
  97. ios.dynamicLink.isi = ios.dynamicLink.isi || '1165103905';
  98. }
  99. android.appName = android.appName || 'Jitsi Meet';
  100. android.appScheme = android.appScheme || 'org.jitsi.meet';
  101. android.downloadLink = android.downloadLink
  102. || 'https://play.google.com/store/apps/details?id=org.jitsi.meet';
  103. android.appPackage = android.appPackage || 'org.jitsi.meet';
  104. android.fDroidUrl = android.fDroidUrl || 'https://f-droid.org/en/packages/org.jitsi.meet/';
  105. if (android.dynamicLink) {
  106. android.dynamicLink.apn = android.dynamicLink.apn || 'org.jitsi.meet';
  107. android.dynamicLink.appCode = android.dynamicLink.appCode || 'w2atb';
  108. android.dynamicLink.ibi = android.dynamicLink.ibi || 'com.atlassian.JitsiMeet.ios';
  109. android.dynamicLink.isi = android.dynamicLink.isi || '1165103905';
  110. }
  111. }
  112. /**
  113. * Common logic to gather buttons that have to notify the api when clicked.
  114. *
  115. * @param {Array} buttonsWithNotifyClick - The array of systme buttons that need to notify the api.
  116. * @param {Array} customButtons - The custom buttons.
  117. * @returns {Array}
  118. */
  119. const buildButtonsArray = (
  120. buttonsWithNotifyClick?: NotifyClickButton[],
  121. customButtons?: {
  122. icon: string;
  123. id: string;
  124. text: string;
  125. }[]
  126. ): NotifyClickButton[] => {
  127. const customButtonsWithNotifyClick = customButtons?.map(({ id }) => {
  128. return {
  129. key: id,
  130. preventExecution: false
  131. };
  132. });
  133. const buttons = Array.isArray(buttonsWithNotifyClick)
  134. ? buttonsWithNotifyClick as NotifyClickButton[]
  135. : [];
  136. if (customButtonsWithNotifyClick) {
  137. buttons.push(...customButtonsWithNotifyClick);
  138. }
  139. return buttons;
  140. };
  141. /**
  142. * Returns the list of toolbar buttons that have to notify the api when clicked.
  143. *
  144. * @param {Object} state - The redux state.
  145. * @returns {Array} - The list of buttons.
  146. */
  147. export function getButtonsWithNotifyClick(
  148. state: IReduxState
  149. ): NotifyClickButton[] {
  150. const { buttonsWithNotifyClick, customToolbarButtons } = state['features/base/config'];
  151. return buildButtonsArray(
  152. buttonsWithNotifyClick,
  153. customToolbarButtons
  154. );
  155. }
  156. /**
  157. * Returns the list of participant menu buttons that have that notify the api when clicked.
  158. *
  159. * @param {Object} state - The redux state.
  160. * @returns {Array} - The list of participant menu buttons.
  161. */
  162. export function getParticipantMenuButtonsWithNotifyClick(
  163. state: IReduxState
  164. ): NotifyClickButton[] {
  165. const { participantMenuButtonsWithNotifyClick, customParticipantMenuButtons } = state['features/base/config'];
  166. return buildButtonsArray(
  167. participantMenuButtonsWithNotifyClick,
  168. customParticipantMenuButtons
  169. );
  170. }
  171. /**
  172. * Returns the notify mode for the specified button.
  173. *
  174. * @param {string} buttonKey - The button key.
  175. * @param {Array} buttonsWithNotifyClick - The buttons with notify click.
  176. * @returns {string|undefined}
  177. */
  178. export const getButtonNotifyMode = (
  179. buttonKey: string,
  180. buttonsWithNotifyClick?: NotifyClickButton[]
  181. ): string | undefined => {
  182. const notify = buttonsWithNotifyClick?.find(
  183. (btn: NotifyClickButton) =>
  184. (typeof btn === 'string' && btn === buttonKey) || (typeof btn === 'object' && btn.key === buttonKey)
  185. );
  186. if (notify) {
  187. return typeof notify === 'string' || notify.preventExecution
  188. ? NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  189. : NOTIFY_CLICK_MODE.ONLY_NOTIFY;
  190. }
  191. };