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.

reducer.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* @flow */
  2. import { assign, ReducerRegistry, set } from '../redux';
  3. import {
  4. CONNECTION_DISCONNECTED,
  5. CONNECTION_ESTABLISHED,
  6. SET_LOCATION_URL
  7. } from './actionTypes';
  8. /**
  9. * Reduces the Redux actions of the feature base/connection.
  10. */
  11. ReducerRegistry.register(
  12. 'features/base/connection',
  13. (state: Object = {}, action: Object) => {
  14. switch (action.type) {
  15. case CONNECTION_DISCONNECTED:
  16. return _connectionDisconnected(state, action);
  17. case CONNECTION_ESTABLISHED:
  18. return _connectionEstablished(state, action);
  19. case SET_LOCATION_URL:
  20. return _setLocationURL(state, action);
  21. }
  22. return state;
  23. });
  24. /**
  25. * Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
  26. * base/connection.
  27. *
  28. * @param {Object} state - The Redux state of the feature base/connection.
  29. * @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
  30. * @private
  31. * @returns {Object} The new state of the feature base/connection after the
  32. * reduction of the specified action.
  33. */
  34. function _connectionDisconnected(
  35. state: Object,
  36. { connection }: { connection: Object }) {
  37. if (state.connection === connection) {
  38. return set(state, 'connection', undefined);
  39. }
  40. return state;
  41. }
  42. /**
  43. * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
  44. * base/connection.
  45. *
  46. * @param {Object} state - The Redux state of the feature base/connection.
  47. * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
  48. * @private
  49. * @returns {Object} The new state of the feature base/connection after the
  50. * reduction of the specified action.
  51. */
  52. function _connectionEstablished(
  53. state: Object,
  54. { connection }: { connection: Object }) {
  55. return set(state, 'connection', connection);
  56. }
  57. /**
  58. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  59. * based on a specific domain.
  60. *
  61. * @param {string} domain - The domain with which the returned options are to be
  62. * populated.
  63. * @private
  64. * @returns {Object}
  65. */
  66. function _constructOptions(domain: string) {
  67. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  68. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  69. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  70. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  71. let boshProtocol;
  72. if (domain === 'beta.meet.jit.si') {
  73. if (typeof window === 'object') {
  74. const windowLocation = window.location;
  75. if (windowLocation) {
  76. // React Native doesn't have a window.location at the time of
  77. // this writing, let alone a window.location.protocol.
  78. boshProtocol = windowLocation.protocol;
  79. }
  80. }
  81. boshProtocol || (boshProtocol = 'http:');
  82. }
  83. // Default to the HTTPS scheme for the BOSH URL.
  84. boshProtocol || (boshProtocol = 'https:');
  85. return {
  86. bosh: `${String(boshProtocol)}//${domain}/http-bind`,
  87. hosts: {
  88. domain,
  89. // Required by:
  90. // - lib-jitsi-meet/modules/xmpp/xmpp.js
  91. muc: `conference.${domain}`
  92. }
  93. };
  94. }
  95. /**
  96. * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
  97. * base/connection.
  98. *
  99. * @param {Object} state - The redux state of the feature base/connection.
  100. * @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
  101. * @private
  102. * @returns {Object} The new state of the feature base/connection after the
  103. * reduction of the specified action.
  104. */
  105. function _setLocationURL(
  106. state: Object,
  107. { locationURL }: { locationURL: ?URL }) {
  108. return assign(state, {
  109. locationURL,
  110. options: locationURL ? _constructOptions(locationURL.host) : undefined
  111. });
  112. }