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

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