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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { ReducerRegistry } from '../redux';
  2. import {
  3. CONNECTION_DISCONNECTED,
  4. CONNECTION_ESTABLISHED,
  5. SET_DOMAIN
  6. } from './actionTypes';
  7. /**
  8. * Initial Redux state.
  9. *
  10. * @type {{
  11. * jitsiConnection: (JitsiConnection|null),
  12. * connectionOptions: Object
  13. * }}
  14. */
  15. const INITIAL_STATE = {
  16. jitsiConnection: null,
  17. connectionOptions: null
  18. };
  19. /**
  20. * Listen for actions that contain the connection object, so that
  21. * it can be stored for use by other action creators.
  22. */
  23. ReducerRegistry.register('features/base/connection',
  24. (state = INITIAL_STATE, action) => {
  25. switch (action.type) {
  26. case CONNECTION_DISCONNECTED:
  27. if (state.jitsiConnection === action.connection) {
  28. return {
  29. ...state,
  30. jitsiConnection: null
  31. };
  32. }
  33. return state;
  34. case CONNECTION_ESTABLISHED:
  35. return {
  36. ...state,
  37. jitsiConnection: action.connection
  38. };
  39. case SET_DOMAIN:
  40. return {
  41. ...state,
  42. connectionOptions: {
  43. ...state.connectionOptions,
  44. ...buildConnectionOptions(action.domain)
  45. }
  46. };
  47. default:
  48. return state;
  49. }
  50. });
  51. /**
  52. * Builds connection options based on domain.
  53. *
  54. * @param {string} domain - Domain name.
  55. * @returns {Object}
  56. */
  57. function buildConnectionOptions(domain) {
  58. // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
  59. // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
  60. // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
  61. // HTTP scheme for the BOSH URL with beta.meet.jit.si on mobile.
  62. let boshProtocol;
  63. if (domain === 'beta.meet.jit.si') {
  64. if (typeof window === 'object') {
  65. const windowLocation = window.location;
  66. if (windowLocation) {
  67. // React Native doesn't have a window.location at the time of
  68. // this writing, let alone a window.location.protocol.
  69. boshProtocol = windowLocation.protocol;
  70. }
  71. }
  72. if (!boshProtocol) {
  73. boshProtocol = 'http:';
  74. }
  75. }
  76. // Default to the HTTPS scheme for the BOSH URL.
  77. if (!boshProtocol) {
  78. boshProtocol = 'https:';
  79. }
  80. return {
  81. bosh: `${boshProtocol}//${domain}/http-bind`,
  82. hosts: {
  83. domain,
  84. focus: `focus.${domain}`,
  85. muc: `conference.${domain}`
  86. }
  87. };
  88. }