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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { ReducerRegistry } from '../redux';
  2. import {
  3. LIB_DISPOSED,
  4. LIB_INIT_ERROR,
  5. LIB_INITIALIZED,
  6. SET_CONFIG
  7. } from './actionTypes';
  8. /**
  9. * The initial state of 'features/base/lib-jitsi-meet'.
  10. *
  11. * @type {{
  12. * config: Object
  13. * }}
  14. */
  15. const INITIAL_STATE = {
  16. /**
  17. * The mandatory configuration to be passed to JitsiMeetJS#init(). The app
  18. * will download config.js from the Jitsi Meet deployment and taks its
  19. * values into account but the values bellow will be enforced (because they
  20. * are essential to the correct execution of the application).
  21. *
  22. * @type {Object}
  23. */
  24. config: {
  25. // FIXME The support for audio levels in lib-jitsi-meet polls the
  26. // statistics of WebRTC at a short interval multiple times a second.
  27. // Unfortunately, React Native is slow to fetch these statistics from
  28. // the native WebRTC API, through the React Native bridge and eventually
  29. // to JavaScript. Because the audio levels are of no interest to the
  30. // mobile app, it is fastest to merely disable them.
  31. disableAudioLevels: true,
  32. // FIXME Lib-jitsi-meet uses HTML script elements to asynchronously load
  33. // certain pieces of JavaScript. Unfortunately, the technique doesn't
  34. // work on React Native (because there are no HTML elements in the first
  35. // place). Fortunately, these pieces of JavaScript currently involve
  36. // third parties and we can temporarily disable them (until we implement
  37. // an alternative to async script elements on React Native).
  38. disableThirdPartyRequests: true
  39. }
  40. };
  41. ReducerRegistry.register(
  42. 'features/base/lib-jitsi-meet',
  43. (state = INITIAL_STATE, action) => {
  44. switch (action.type) {
  45. case LIB_DISPOSED:
  46. return INITIAL_STATE;
  47. case LIB_INIT_ERROR:
  48. return {
  49. ...state,
  50. initError: action.error,
  51. initialized: false
  52. };
  53. case LIB_INITIALIZED:
  54. return {
  55. ...state,
  56. initError: undefined,
  57. initialized: true
  58. };
  59. case SET_CONFIG:
  60. return _setConfig(state, action);
  61. default:
  62. return state;
  63. }
  64. });
  65. /**
  66. * Reduces a specific Redux action SET_CONFIG of the feature
  67. * base/lib-jitsi-meet.
  68. *
  69. * @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
  70. * @param {Action} action - The Redux action SET_CONFIG to reduce.
  71. * @private
  72. * @returns {Object} The new state of the feature base/lib-jitsi-meet after the
  73. * reduction of the specified action.
  74. */
  75. function _setConfig(state, action) {
  76. return {
  77. ...state,
  78. config: {
  79. ...action.config,
  80. // The config of INITIAL_STATE is meant to override the config
  81. // downloaded from the Jitsi Meet deployment because the former
  82. // contains values that are mandatory.
  83. ...INITIAL_STATE.config
  84. }
  85. };
  86. }