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.

actions.any.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import _ from 'lodash';
  2. import { IState } from '../../app/types';
  3. import {
  4. appendURLParam,
  5. getBackendSafeRoomName,
  6. parseURIString
  7. } from '../util/uri';
  8. import logger from './logger';
  9. /**
  10. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  11. * based on the redux state.
  12. *
  13. * @param {Object} state - The redux state.
  14. * @returns {Object} The options to be passed to the constructor of
  15. * {@code JitsiConnection}.
  16. */
  17. export function constructOptions(state: IState) {
  18. // Deep clone the options to make sure we don't modify the object in the
  19. // redux store.
  20. const options = _.cloneDeep(state['features/base/config']);
  21. let { bosh, websocket } = options;
  22. // TESTING: Only enable WebSocket for some percentage of users.
  23. if (websocket && navigator.product === 'ReactNative') {
  24. if ((Math.random() * 100) >= (options?.testing?.mobileXmppWsThreshold ?? 0)) {
  25. websocket = undefined;
  26. }
  27. }
  28. // Normalize the BOSH URL.
  29. if (bosh && !websocket) {
  30. const { locationURL } = state['features/base/connection'];
  31. if (bosh.startsWith('//')) {
  32. // By default our config.js doesn't include the protocol.
  33. bosh = `${locationURL?.protocol}${bosh}`;
  34. } else if (bosh.startsWith('/')) {
  35. // Handle relative URLs, which won't work on mobile.
  36. const {
  37. protocol,
  38. host,
  39. contextRoot
  40. } = parseURIString(locationURL?.href);
  41. bosh = `${protocol}//${host}${contextRoot || '/'}${bosh.substr(1)}`;
  42. }
  43. }
  44. // WebSocket is preferred over BOSH.
  45. const serviceUrl = websocket || bosh;
  46. logger.log(`Using service URL ${serviceUrl}`);
  47. // Append room to the URL's search.
  48. const { room } = state['features/base/conference'];
  49. if (serviceUrl && room) {
  50. const roomName = getBackendSafeRoomName(room);
  51. options.serviceUrl = appendURLParam(serviceUrl, 'room', roomName ?? '');
  52. if (options.websocketKeepAliveUrl) {
  53. options.websocketKeepAliveUrl = appendURLParam(options.websocketKeepAliveUrl, 'room', roomName ?? '');
  54. }
  55. }
  56. return options;
  57. }