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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * @private
  57. * @returns {Object}
  58. */
  59. function _constructConnectionOptions(domain) {
  60. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  61. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  62. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  63. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  64. let boshProtocol;
  65. if (domain === 'beta.meet.jit.si') {
  66. if (typeof window === 'object') {
  67. const windowLocation = window.location;
  68. if (windowLocation) {
  69. // React Native doesn't have a window.location at the time of
  70. // this writing, let alone a window.location.protocol.
  71. boshProtocol = windowLocation.protocol;
  72. }
  73. }
  74. boshProtocol || (boshProtocol = 'http:');
  75. }
  76. // Default to the HTTPS scheme for the BOSH URL.
  77. boshProtocol || (boshProtocol = 'https:');
  78. return {
  79. bosh: `${boshProtocol}//${domain}/http-bind`,
  80. hosts: {
  81. domain,
  82. focus: `focus.${domain}`,
  83. muc: `conference.${domain}`
  84. }
  85. };
  86. }
  87. /**
  88. * Reduces a specific Redux action SET_DOMAIN of the feature base/connection.
  89. *
  90. * @param {Object} state - The Redux state of the feature base/connection.
  91. * @param {Action} action - The Redux action SET_DOMAIN to reduce.
  92. * @private
  93. * @returns {Object} The new state of the feature base/connection after the
  94. * reduction of the specified action.
  95. */
  96. function _setDomain(state, action) {
  97. return {
  98. ...state,
  99. connectionOptions: {
  100. ...state.connectionOptions,
  101. ..._constructConnectionOptions(action.domain)
  102. }
  103. };
  104. }