您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* @flow */
  2. import { assign, ReducerRegistry } 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. error: undefined
  69. });
  70. }
  71. /**
  72. * Reduces a specific Redux action CONNECTION_FAILED of the feature
  73. * base/connection.
  74. *
  75. * @param {Object} state - The Redux state of the feature base/connection.
  76. * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
  77. * @private
  78. * @returns {Object} The new state of the feature base/connection after the
  79. * reduction of the specified action.
  80. */
  81. function _connectionFailed(
  82. state: Object,
  83. { connection, error }: {
  84. connection: Object,
  85. error: Object | string
  86. }) {
  87. if (state.connection && state.connection !== connection) {
  88. return state;
  89. }
  90. return assign(state, {
  91. connecting: undefined,
  92. connection: undefined,
  93. error
  94. });
  95. }
  96. /**
  97. * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
  98. * base/connection.
  99. *
  100. * @param {Object} state - The Redux state of the feature base/connection.
  101. * @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
  102. * @private
  103. * @returns {Object} The new state of the feature base/connection after the
  104. * reduction of the specified action.
  105. */
  106. function _connectionWillConnect(
  107. state: Object,
  108. { connection }: { connection: Object }) {
  109. return assign(state, {
  110. connecting: connection,
  111. error: undefined
  112. });
  113. }
  114. /**
  115. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  116. * based on a specific location URL.
  117. *
  118. * @param {string} locationURL - The location URL with which the returned
  119. * options are to be constructed.
  120. * @private
  121. * @returns {Object} The options to be passed to the constructor of
  122. * {@code JitsiConnection} based on the location URL.
  123. */
  124. function _constructOptions(locationURL: URL) {
  125. const locationURI = parseURIString(locationURL.href);
  126. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  127. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  128. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  129. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  130. let { protocol } = locationURI;
  131. const domain = locationURI.hostname;
  132. if (!protocol && domain === 'beta.meet.jit.si') {
  133. const windowLocation = window.location;
  134. windowLocation && (protocol = windowLocation.protocol);
  135. protocol || (protocol = 'http:');
  136. }
  137. // Default to the HTTPS scheme for the BOSH URL.
  138. protocol || (protocol = 'https:');
  139. return {
  140. bosh:
  141. `${String(protocol)}//${domain}${locationURI.contextRoot || '/'
  142. }http-bind`,
  143. hosts: {
  144. domain,
  145. // Required by:
  146. // - lib-jitsi-meet/modules/xmpp/xmpp.js
  147. muc: `conference.${domain}`
  148. }
  149. };
  150. }
  151. /**
  152. * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
  153. * base/connection.
  154. *
  155. * @param {Object} state - The redux state of the feature base/connection.
  156. * @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
  157. * @private
  158. * @returns {Object} The new state of the feature base/connection after the
  159. * reduction of the specified action.
  160. */
  161. function _setLocationURL(
  162. state: Object,
  163. { locationURL }: { locationURL: ?URL }) {
  164. return assign(state, {
  165. locationURL,
  166. options: locationURL ? _constructOptions(locationURL) : undefined
  167. });
  168. }