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

reducer.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { ReducerRegistry, setStateProperty } from '../redux';
  2. import {
  3. CONNECTION_DISCONNECTED,
  4. CONNECTION_ESTABLISHED,
  5. SET_DOMAIN
  6. } from './actionTypes';
  7. /**
  8. * Reduces the Redux actions of the feature base/connection.
  9. */
  10. ReducerRegistry.register('features/base/connection', (state = {}, action) => {
  11. switch (action.type) {
  12. case CONNECTION_DISCONNECTED:
  13. return _connectionDisconnected(state, action);
  14. case CONNECTION_ESTABLISHED:
  15. return _connectionEstablished(state, action);
  16. case SET_DOMAIN:
  17. return _setDomain(state, action);
  18. }
  19. return state;
  20. });
  21. /**
  22. * Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
  23. * base/connection.
  24. *
  25. * @param {Object} state - The Redux state of the feature base/connection.
  26. * @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
  27. * @private
  28. * @returns {Object} The new state of the feature base/connection after the
  29. * reduction of the specified action.
  30. */
  31. function _connectionDisconnected(state, action) {
  32. if (state.connection === action.connection) {
  33. return setStateProperty(state, 'connection', undefined);
  34. }
  35. return state;
  36. }
  37. /**
  38. * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
  39. * base/connection.
  40. *
  41. * @param {Object} state - The Redux state of the feature base/connection.
  42. * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
  43. * @private
  44. * @returns {Object} The new state of the feature base/connection after the
  45. * reduction of the specified action.
  46. */
  47. function _connectionEstablished(state, action) {
  48. return setStateProperty(state, 'connection', action.connection);
  49. }
  50. /**
  51. * Constructs options to be passed to the constructor of JitsiConnection based
  52. * on a specific domain.
  53. *
  54. * @param {string} domain - The domain with which the returned options are to be
  55. * populated.
  56. * @returns {Object}
  57. */
  58. function _constructConnectionOptions(domain) {
  59. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  60. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  61. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  62. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  63. let boshProtocol;
  64. if (domain === 'beta.meet.jit.si') {
  65. if (typeof window === 'object') {
  66. const windowLocation = window.location;
  67. if (windowLocation) {
  68. // React Native doesn't have a window.location at the time of
  69. // this writing, let alone a window.location.protocol.
  70. boshProtocol = windowLocation.protocol;
  71. }
  72. }
  73. boshProtocol || (boshProtocol = 'http:');
  74. }
  75. // Default to the HTTPS scheme for the BOSH URL.
  76. boshProtocol || (boshProtocol = 'https:');
  77. return {
  78. bosh: `${boshProtocol}//${domain}/http-bind`,
  79. hosts: {
  80. domain,
  81. focus: `focus.${domain}`,
  82. muc: `conference.${domain}`
  83. }
  84. };
  85. }
  86. /**
  87. * Reduces a specific Redux action SET_DOMAIN of the feature base/connection.
  88. *
  89. * @param {Object} state - The Redux state of the feature base/connection.
  90. * @param {Action} action - The Redux action SET_DOMAIN to reduce.
  91. * @private
  92. * @returns {Object} The new state of the feature base/connection after the
  93. * reduction of the specified action.
  94. */
  95. function _setDomain(state, action) {
  96. return {
  97. ...state,
  98. connectionOptions: {
  99. ...state.connectionOptions,
  100. ..._constructConnectionOptions(action.domain)
  101. }
  102. };
  103. }