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

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