Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.web.ts 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. IDeeplinkingDesktopConfig,
  8. IDeeplinkingMobileConfig,
  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 IDeeplinkingDesktopConfig,
  86. android = {} as IDeeplinkingMobileConfig,
  87. ios = {} as IDeeplinkingMobileConfig
  88. } = deeplinking;
  89. desktop.appName = desktop.appName || 'Jitsi Meet';
  90. desktop.appScheme = desktop.appScheme || 'jitsi-meet';
  91. desktop.download = desktop.download || {};
  92. desktop.download.windows = desktop.download.windows
  93. || 'https://github.com/jitsi/jitsi-meet-electron/releases/latest/download/jitsi-meet.exe';
  94. desktop.download.macos = desktop.download.macos
  95. || 'https://github.com/jitsi/jitsi-meet-electron/releases/latest/download/jitsi-meet.dmg';
  96. desktop.download.linux = desktop.download.linux
  97. || 'https://github.com/jitsi/jitsi-meet-electron/releases/latest/download/jitsi-meet-x86_64.AppImage';
  98. ios.appName = ios.appName || 'Jitsi Meet';
  99. ios.appScheme = ios.appScheme || 'org.jitsi.meet';
  100. ios.downloadLink = ios.downloadLink
  101. || 'https://itunes.apple.com/us/app/jitsi-meet/id1165103905';
  102. if (ios.dynamicLink) {
  103. ios.dynamicLink.apn = ios.dynamicLink.apn || 'org.jitsi.meet';
  104. ios.dynamicLink.appCode = ios.dynamicLink.appCode || 'w2atb';
  105. ios.dynamicLink.ibi = ios.dynamicLink.ibi || 'com.atlassian.JitsiMeet.ios';
  106. ios.dynamicLink.isi = ios.dynamicLink.isi || '1165103905';
  107. }
  108. android.appName = android.appName || 'Jitsi Meet';
  109. android.appScheme = android.appScheme || 'org.jitsi.meet';
  110. android.downloadLink = android.downloadLink
  111. || 'https://play.google.com/store/apps/details?id=org.jitsi.meet';
  112. android.appPackage = android.appPackage || 'org.jitsi.meet';
  113. android.fDroidUrl = android.fDroidUrl || 'https://f-droid.org/en/packages/org.jitsi.meet/';
  114. if (android.dynamicLink) {
  115. android.dynamicLink.apn = android.dynamicLink.apn || 'org.jitsi.meet';
  116. android.dynamicLink.appCode = android.dynamicLink.appCode || 'w2atb';
  117. android.dynamicLink.ibi = android.dynamicLink.ibi || 'com.atlassian.JitsiMeet.ios';
  118. android.dynamicLink.isi = android.dynamicLink.isi || '1165103905';
  119. }
  120. }
  121. /**
  122. * Common logic to gather buttons that have to notify the api when clicked.
  123. *
  124. * @param {Array} buttonsWithNotifyClick - The array of systme buttons that need to notify the api.
  125. * @param {Array} customButtons - The custom buttons.
  126. * @returns {Array}
  127. */
  128. const buildButtonsArray = (
  129. buttonsWithNotifyClick?: NotifyClickButton[],
  130. customButtons?: {
  131. icon: string;
  132. id: string;
  133. text: string;
  134. }[]
  135. ): NotifyClickButton[] => {
  136. const customButtonsWithNotifyClick = customButtons?.map(({ id }) => {
  137. return {
  138. key: id,
  139. preventExecution: false
  140. };
  141. });
  142. const buttons = Array.isArray(buttonsWithNotifyClick)
  143. ? buttonsWithNotifyClick as NotifyClickButton[]
  144. : [];
  145. if (customButtonsWithNotifyClick) {
  146. buttons.push(...customButtonsWithNotifyClick);
  147. }
  148. return buttons;
  149. };
  150. /**
  151. * Returns the list of toolbar buttons that have to notify the api when clicked.
  152. *
  153. * @param {Object} state - The redux state.
  154. * @returns {Array} - The list of buttons.
  155. */
  156. export function getButtonsWithNotifyClick(
  157. state: IReduxState
  158. ): NotifyClickButton[] {
  159. const { buttonsWithNotifyClick, customToolbarButtons } = state['features/base/config'];
  160. return buildButtonsArray(
  161. buttonsWithNotifyClick,
  162. customToolbarButtons
  163. );
  164. }
  165. /**
  166. * Returns the list of participant menu buttons that have that notify the api when clicked.
  167. *
  168. * @param {Object} state - The redux state.
  169. * @returns {Array} - The list of participant menu buttons.
  170. */
  171. export function getParticipantMenuButtonsWithNotifyClick(
  172. state: IReduxState
  173. ): NotifyClickButton[] {
  174. const { participantMenuButtonsWithNotifyClick, customParticipantMenuButtons } = state['features/base/config'];
  175. return buildButtonsArray(
  176. participantMenuButtonsWithNotifyClick,
  177. customParticipantMenuButtons
  178. );
  179. }
  180. /**
  181. * Returns the notify mode for the specified button.
  182. *
  183. * @param {string} buttonKey - The button key.
  184. * @param {Array} buttonsWithNotifyClick - The buttons with notify click.
  185. * @returns {string|undefined}
  186. */
  187. export const getButtonNotifyMode = (
  188. buttonKey: string,
  189. buttonsWithNotifyClick?: NotifyClickButton[]
  190. ): string | undefined => {
  191. const notify = buttonsWithNotifyClick?.find(
  192. (btn: NotifyClickButton) =>
  193. (typeof btn === 'string' && btn === buttonKey) || (typeof btn === 'object' && btn.key === buttonKey)
  194. );
  195. if (notify) {
  196. return typeof notify === 'string' || notify.preventExecution
  197. ? NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  198. : NOTIFY_CLICK_MODE.ONLY_NOTIFY;
  199. }
  200. };