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

functions.web.ts 7.0KB

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