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

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