You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.native.ts 1.7KB

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