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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* @flow */
  2. import { assign, ReducerRegistry, set } from '../redux';
  3. import { parseURIString } from '../util';
  4. import {
  5. CONNECTION_DISCONNECTED,
  6. CONNECTION_ESTABLISHED,
  7. CONNECTION_FAILED,
  8. CONNECTION_WILL_CONNECT,
  9. SET_LOCATION_URL
  10. } from './actionTypes';
  11. /**
  12. * Reduces the Redux actions of the feature base/connection.
  13. */
  14. ReducerRegistry.register(
  15. 'features/base/connection',
  16. (state: Object = {}, action: Object) => {
  17. switch (action.type) {
  18. case CONNECTION_DISCONNECTED:
  19. return _connectionDisconnected(state, action);
  20. case CONNECTION_ESTABLISHED:
  21. return _connectionEstablished(state, action);
  22. case CONNECTION_FAILED:
  23. return _connectionFailed(state, action);
  24. case CONNECTION_WILL_CONNECT:
  25. return _connectionWillConnect(state, action);
  26. case SET_LOCATION_URL:
  27. return _setLocationURL(state, action);
  28. }
  29. return state;
  30. });
  31. /**
  32. * Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
  33. * base/connection.
  34. *
  35. * @param {Object} state - The Redux state of the feature base/connection.
  36. * @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
  37. * @private
  38. * @returns {Object} The new state of the feature base/connection after the
  39. * reduction of the specified action.
  40. */
  41. function _connectionDisconnected(
  42. state: Object,
  43. { connection }: { connection: Object }) {
  44. if (state.connection !== connection) {
  45. return state;
  46. }
  47. return assign(state, {
  48. connecting: undefined,
  49. connection: undefined
  50. });
  51. }
  52. /**
  53. * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
  54. * base/connection.
  55. *
  56. * @param {Object} state - The Redux state of the feature base/connection.
  57. * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
  58. * @private
  59. * @returns {Object} The new state of the feature base/connection after the
  60. * reduction of the specified action.
  61. */
  62. function _connectionEstablished(
  63. state: Object,
  64. { connection }: { connection: Object }) {
  65. return assign(state, {
  66. connecting: undefined,
  67. connection
  68. });
  69. }
  70. /**
  71. * Reduces a specific Redux action CONNECTION_FAILED of the feature
  72. * base/connection.
  73. *
  74. * @param {Object} state - The Redux state of the feature base/connection.
  75. * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
  76. * @private
  77. * @returns {Object} The new state of the feature base/connection after the
  78. * reduction of the specified action.
  79. */
  80. function _connectionFailed(
  81. state: Object,
  82. { connection }: { connection: Object }) {
  83. if (state.connection && state.connection !== connection) {
  84. return state;
  85. }
  86. return assign(state, {
  87. connecting: undefined,
  88. connection: undefined
  89. });
  90. }
  91. /**
  92. * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
  93. * base/connection.
  94. *
  95. * @param {Object} state - The Redux state of the feature base/connection.
  96. * @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
  97. * @private
  98. * @returns {Object} The new state of the feature base/connection after the
  99. * reduction of the specified action.
  100. */
  101. function _connectionWillConnect(
  102. state: Object,
  103. { connection }: { connection: Object }) {
  104. return set(state, 'connecting', connection);
  105. }
  106. /**
  107. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  108. * based on a specific location URL.
  109. *
  110. * @param {string} locationURL - The location URL with which the returned
  111. * options are to be constructed.
  112. * @private
  113. * @returns {Object} The options to be passed to the constructor of
  114. * {@code JitsiConnection} based on the location URL.
  115. */
  116. function _constructOptions(locationURL: URL) {
  117. const locationURI = parseURIString(locationURL.href);
  118. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  119. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  120. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  121. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  122. let { protocol } = locationURI;
  123. const domain = locationURI.hostname;
  124. if (!protocol && domain === 'beta.meet.jit.si') {
  125. const windowLocation = window.location;
  126. windowLocation && (protocol = windowLocation.protocol);
  127. protocol || (protocol = 'http:');
  128. }
  129. // Default to the HTTPS scheme for the BOSH URL.
  130. protocol || (protocol = 'https:');
  131. return {
  132. bosh:
  133. `${String(protocol)}//${domain}${locationURI.contextRoot || '/'
  134. }http-bind`,
  135. hosts: {
  136. domain,
  137. // Required by:
  138. // - lib-jitsi-meet/modules/xmpp/xmpp.js
  139. muc: `conference.${domain}`
  140. }
  141. };
  142. }
  143. /**
  144. * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
  145. * base/connection.
  146. *
  147. * @param {Object} state - The redux state of the feature base/connection.
  148. * @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
  149. * @private
  150. * @returns {Object} The new state of the feature base/connection after the
  151. * reduction of the specified action.
  152. */
  153. function _setLocationURL(
  154. state: Object,
  155. { locationURL }: { locationURL: ?URL }) {
  156. return assign(state, {
  157. locationURL,
  158. options: locationURL ? _constructOptions(locationURL) : undefined
  159. });
  160. }