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

functions.any.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { toState } from '../base/redux/functions';
  4. /**
  5. * Extracts the fqn part from a path, where fqn represents
  6. * tenant/roomName.
  7. *
  8. * @param {Object} state - A redux state.
  9. * @returns {string}
  10. */
  11. export function extractFqnFromPath(state?: IReduxState) {
  12. let pathname;
  13. if (window.location.pathname) {
  14. pathname = window.location.pathname;
  15. } else if (state?.['features/base/connection']) {
  16. pathname = state['features/base/connection'].locationURL?.pathname ?? '';
  17. } else {
  18. return '';
  19. }
  20. const parts = pathname.split('/');
  21. const len = parts.length;
  22. return parts.length > 2 ? `${parts[len - 2]}/${parts[len - 1]}` : parts[1];
  23. }
  24. /**
  25. * Returns the url used for fetching dynamic branding.
  26. *
  27. * @param {Object | Function} stateful - The redux store, state, or
  28. * {@code getState} function.
  29. * @returns {string}
  30. */
  31. export async function getDynamicBrandingUrl(stateful: IStateful) {
  32. const state = toState(stateful);
  33. // NB: On web this is dispatched really early, before the config has been stored in the
  34. // state. Thus, fetch it from the window global.
  35. const config
  36. = navigator.product === 'ReactNative' ? state['features/base/config'] : window.config;
  37. const { dynamicBrandingUrl } = config;
  38. if (dynamicBrandingUrl) {
  39. return dynamicBrandingUrl;
  40. }
  41. const { brandingDataUrl: baseUrl } = config;
  42. const fqn = extractFqnFromPath(state);
  43. if (baseUrl && fqn) {
  44. return `${baseUrl}?conferenceFqn=${encodeURIComponent(fqn)}`;
  45. }
  46. }
  47. /**
  48. * Selector used for getting the load state of the dynamic branding data.
  49. *
  50. * @param {Object} state - Global state of the app.
  51. * @returns {boolean}
  52. */
  53. export function isDynamicBrandingDataLoaded(state: IReduxState) {
  54. return state['features/dynamic-branding'].customizationReady;
  55. }