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.3KB

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