Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.any.js 2.1KB

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