Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

functions.native.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Platform } from 'react-native';
  2. import { IConfig } from '../base/config/configType';
  3. import { _getTokenAuthState } from './functions.any';
  4. export * from './functions.any';
  5. /**
  6. * Creates the URL pointing to JWT token authentication service. It is
  7. * formatted from the 'urlPattern' argument which can contain the following
  8. * constants:
  9. * '{room}' - name of the conference room passed as <tt>roomName</tt>
  10. * argument to this method.
  11. *
  12. * @param {Object} config - Configuration state object from store. A URL pattern pointing to the login service.
  13. * @param {URL} locationURL - The location URL.
  14. * @param {Object} options: - Config options {
  15. * audioMuted: boolean | undefined
  16. * audioOnlyEnabled: boolean | undefined,
  17. * skipPrejoin: boolean | undefined,
  18. * videoMuted: boolean | undefined
  19. * }.
  20. * @param {string?} roomName - The room name.
  21. * @param {string?} tenant - The tenant name if any.
  22. *
  23. * @returns {Promise<string|undefined>} - The URL pointing to JWT login service or
  24. * <tt>undefined</tt> if the pattern stored in config is not a string and the URL can not be
  25. * constructed.
  26. */
  27. export const getTokenAuthUrl = (
  28. config: IConfig,
  29. locationURL: URL,
  30. options: {
  31. audioMuted: boolean | undefined;
  32. audioOnlyEnabled: boolean | undefined;
  33. skipPrejoin: boolean | undefined;
  34. videoMuted: boolean | undefined;
  35. },
  36. roomName: string | undefined,
  37. // eslint-disable-next-line max-params
  38. tenant: string | undefined): Promise<string | undefined> => {
  39. const {
  40. audioMuted = false,
  41. audioOnlyEnabled = false,
  42. skipPrejoin = false,
  43. videoMuted = false
  44. } = options;
  45. let url = config.tokenAuthUrl;
  46. if (!url || !roomName) {
  47. return Promise.resolve(undefined);
  48. }
  49. if (url.indexOf('{state}')) {
  50. const state = _getTokenAuthState(
  51. locationURL,
  52. {
  53. audioMuted,
  54. audioOnlyEnabled,
  55. skipPrejoin,
  56. videoMuted
  57. },
  58. roomName,
  59. tenant
  60. );
  61. // Append ios=true or android=true to the token URL.
  62. // @ts-ignore
  63. state[Platform.OS] = true;
  64. url = url.replace('{state}', encodeURIComponent(JSON.stringify(state)));
  65. }
  66. return Promise.resolve(url.replace('{room}', roomName));
  67. };