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.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // @flow
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import { BILLING_ID, VPAAS_TENANT_PREFIX } from './constants';
  4. import logger from './logger';
  5. /**
  6. * Returns the full vpaas tenant if available, given a path.
  7. *
  8. * @param {string} path - The meeting url path.
  9. * @returns {string}
  10. */
  11. export function extractVpaasTenantFromPath(path: string) {
  12. const [ , tenant ] = path.split('/');
  13. if (tenant.startsWith(VPAAS_TENANT_PREFIX)) {
  14. return tenant;
  15. }
  16. return '';
  17. }
  18. /**
  19. * Returns true if the current meeting is a vpaas one.
  20. *
  21. * @param {Object} state - The state of the app.
  22. * @returns {boolean}
  23. */
  24. export function isVpaasMeeting(state: Object) {
  25. return Boolean(
  26. state['features/base/config'].billingCounterUrl
  27. && state['features/base/jwt'].jwt
  28. && extractVpaasTenantFromPath(
  29. state['features/base/connection'].locationURL.pathname)
  30. );
  31. }
  32. /**
  33. * Sends a billing counter request.
  34. *
  35. * @param {Object} reqData - The request info.
  36. * @param {string} reqData.baseUrl - The base url for the request.
  37. * @param {string} billingId - The unique id of the client.
  38. * @param {string} jwt - The JWT token.
  39. * @param {string} tenat - The client tenant.
  40. * @returns {void}
  41. */
  42. export async function sendCountRequest({ baseUrl, billingId, jwt, tenant }: {
  43. baseUrl: string,
  44. billingId: string,
  45. jwt: string,
  46. tenant: string
  47. }) {
  48. const fullUrl = `${baseUrl}/${encodeURIComponent(tenant)}/${billingId}`;
  49. const headers = {
  50. 'Authorization': `Bearer ${jwt}`
  51. };
  52. try {
  53. const res = await fetch(fullUrl, {
  54. method: 'GET',
  55. headers
  56. });
  57. if (!res.ok) {
  58. logger.error('Status error:', res.status);
  59. }
  60. } catch (err) {
  61. logger.error('Could not send request', err);
  62. }
  63. }
  64. /**
  65. * Returns the stored billing id.
  66. *
  67. * @returns {string}
  68. */
  69. export function getBillingId() {
  70. return jitsiLocalStorage.getItem(BILLING_ID);
  71. }
  72. /**
  73. * Stores the billing id.
  74. *
  75. * @param {string} value - The id to be stored.
  76. * @returns {void}
  77. */
  78. export function setBillingId(value: string) {
  79. jitsiLocalStorage.setItem(BILLING_ID, value);
  80. }