Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

functions.native.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 {string} roomName - The name of the conference room for which the user will be authenticated.
  14. * @param {string} tenant - The name of the conference tenant.
  15. * @param {string} skipPrejoin - The name of the conference room for which the user will be authenticated.
  16. * @param {URL} locationURL - The location URL.
  17. *
  18. * @returns {Promise<string|undefined>} - The URL pointing to JWT login service or
  19. * <tt>undefined</tt> if the pattern stored in config is not a string and the URL can not be
  20. * constructed.
  21. */
  22. export const getTokenAuthUrl = (
  23. config: IConfig,
  24. roomName: string | undefined,
  25. tenant: string | undefined,
  26. skipPrejoin: boolean | undefined = false,
  27. // eslint-disable-next-line max-params
  28. locationURL: URL): Promise<string | undefined> => {
  29. let url = config.tokenAuthUrl;
  30. if (!url || !roomName) {
  31. return Promise.resolve(undefined);
  32. }
  33. if (url.indexOf('{state}')) {
  34. const state = _getTokenAuthState(roomName, tenant, skipPrejoin, locationURL);
  35. // Append ios=true or android=true to the token URL.
  36. // @ts-ignore
  37. state[Platform.OS] = true;
  38. url = url.replace('{state}', encodeURIComponent(JSON.stringify(state)));
  39. }
  40. return Promise.resolve(url.replace('{room}', roomName));
  41. };