Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 set(state, 'connection', undefined);
  45. }
  46. return state;
  47. }
  48. /**
  49. * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
  50. * base/connection.
  51. *
  52. * @param {Object} state - The Redux state of the feature base/connection.
  53. * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
  54. * @private
  55. * @returns {Object} The new state of the feature base/connection after the
  56. * reduction of the specified action.
  57. */
  58. function _connectionEstablished(
  59. state: Object,
  60. { connection }: { connection: Object }) {
  61. return assign(state, {
  62. connecting: undefined,
  63. connection
  64. });
  65. }
  66. /* eslint-disable no-unused-vars */
  67. /**
  68. * Reduces a specific Redux action CONNECTION_FAILED of the feature
  69. * base/connection.
  70. *
  71. * @param {Object} state - The Redux state of the feature base/connection.
  72. * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
  73. * @private
  74. * @returns {Object} The new state of the feature base/connection after the
  75. * reduction of the specified action.
  76. */
  77. function _connectionFailed(state: Object, action: Object) {
  78. return set(state, 'connecting', undefined);
  79. }
  80. /* eslint-enable no-unused-vars */
  81. /**
  82. * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
  83. * base/connection.
  84. *
  85. * @param {Object} state - The Redux state of the feature base/connection.
  86. * @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
  87. * @private
  88. * @returns {Object} The new state of the feature base/connection after the
  89. * reduction of the specified action.
  90. */
  91. function _connectionWillConnect(state: Object, action: Object) {
  92. return set(state, 'connecting', action.connection);
  93. }
  94. /**
  95. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  96. * based on a specific domain.
  97. *
  98. * @param {string} domain - The domain with which the returned options are to be
  99. * populated.
  100. * @private
  101. * @returns {Object}
  102. */
  103. function _constructOptions(domain: string) {
  104. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  105. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  106. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  107. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  108. let boshProtocol;
  109. if (domain === 'beta.meet.jit.si') {
  110. if (typeof window === 'object') {
  111. const windowLocation = window.location;
  112. if (windowLocation) {
  113. // React Native doesn't have a window.location at the time of
  114. // this writing, let alone a window.location.protocol.
  115. boshProtocol = windowLocation.protocol;
  116. }
  117. }
  118. boshProtocol || (boshProtocol = 'http:');
  119. }
  120. // Default to the HTTPS scheme for the BOSH URL.
  121. boshProtocol || (boshProtocol = 'https:');
  122. return {
  123. bosh: `${String(boshProtocol)}//${domain}/http-bind`,
  124. hosts: {
  125. domain,
  126. // Required by:
  127. // - lib-jitsi-meet/modules/xmpp/xmpp.js
  128. muc: `conference.${domain}`
  129. }
  130. };
  131. }
  132. /**
  133. * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
  134. * base/connection.
  135. *
  136. * @param {Object} state - The redux state of the feature base/connection.
  137. * @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
  138. * @private
  139. * @returns {Object} The new state of the feature base/connection after the
  140. * reduction of the specified action.
  141. */
  142. function _setLocationURL(
  143. state: Object,
  144. { locationURL }: { locationURL: ?URL }) {
  145. return assign(state, {
  146. locationURL,
  147. options: locationURL ? _constructOptions(locationURL.host) : undefined
  148. });
  149. }