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

functions.any.ts 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { toState } from '../base/redux/functions';
  4. import logger from './logger';
  5. /**
  6. * Extracts the fqn part from a path, where fqn represents
  7. * tenant/roomName.
  8. *
  9. * @param {Object} state - A redux state.
  10. * @returns {string}
  11. */
  12. export function extractFqnFromPath(state?: IReduxState) {
  13. let pathname;
  14. if (window.location.pathname) {
  15. pathname = window.location.pathname;
  16. } else if (state?.['features/base/connection']) {
  17. pathname = state['features/base/connection'].locationURL?.pathname ?? '';
  18. } else {
  19. return '';
  20. }
  21. const parts = pathname.split('/');
  22. const len = parts.length;
  23. return parts.length > 2 ? `${parts[len - 2]}/${parts[len - 1]}` : parts[1];
  24. }
  25. /**
  26. * Returns the url used for fetching dynamic branding.
  27. *
  28. * @param {Object | Function} stateful - The redux store, state, or
  29. * {@code getState} function.
  30. * @returns {string}
  31. */
  32. export async function getDynamicBrandingUrl(stateful: IStateful) {
  33. const state = toState(stateful);
  34. // NB: On web this is dispatched really early, before the config has been stored in the
  35. // state. Thus, fetch it from the window global.
  36. const config
  37. = navigator.product === 'ReactNative' ? state['features/base/config'] : window.config;
  38. const { dynamicBrandingUrl } = config;
  39. if (dynamicBrandingUrl) {
  40. return dynamicBrandingUrl;
  41. }
  42. const { brandingDataUrl: baseUrl } = config;
  43. const fqn = extractFqnFromPath(state);
  44. if (baseUrl && fqn) {
  45. return `${baseUrl}?conferenceFqn=${encodeURIComponent(fqn)}`;
  46. }
  47. }
  48. /**
  49. * Selector used for getting the load state of the dynamic branding data.
  50. *
  51. * @param {Object} state - Global state of the app.
  52. * @returns {boolean}
  53. */
  54. export function isDynamicBrandingDataLoaded(state: IReduxState) {
  55. return state['features/dynamic-branding'].customizationReady;
  56. }
  57. /**
  58. * Fetch SVG XMLs from branding icons urls.
  59. *
  60. * @param {Object} customIcons - The map of branded icons.
  61. * @returns {Object}
  62. */
  63. export const fetchCustomIcons = async (customIcons: Record<string, string>) => {
  64. const localCustomIcons: Record<string, string> = {};
  65. for (const [ key, url ] of Object.entries(customIcons)) {
  66. try {
  67. const response = await fetch(url);
  68. if (response.ok) {
  69. const svgXml = await response.text();
  70. localCustomIcons[key] = svgXml;
  71. } else {
  72. logger.error(`Failed to fetch ${url}. Status: ${response.status}`);
  73. }
  74. } catch (error) {
  75. logger.error(`Error fetching ${url}:`, error);
  76. }
  77. }
  78. return localCustomIcons;
  79. };