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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { ReducerRegistry } from '../redux';
  2. import {
  3. LIB_DID_DISPOSE,
  4. LIB_DID_INIT,
  5. LIB_INIT_ERROR,
  6. SET_CONFIG,
  7. SET_WEBRTC_READY
  8. } from './actionTypes';
  9. /**
  10. * The initial state of 'features/base/lib-jitsi-meet'.
  11. *
  12. * @type {{
  13. * config: Object
  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. }
  41. };
  42. ReducerRegistry.register(
  43. 'features/base/lib-jitsi-meet',
  44. (state = INITIAL_STATE, action) => {
  45. switch (action.type) {
  46. case LIB_DID_DISPOSE:
  47. return INITIAL_STATE;
  48. case LIB_DID_INIT:
  49. return {
  50. ...state,
  51. initError: undefined,
  52. initialized: true
  53. };
  54. case LIB_INIT_ERROR:
  55. return {
  56. ...state,
  57. initError: action.error,
  58. initialized: false
  59. };
  60. case SET_CONFIG:
  61. return _setConfig(state, action);
  62. case SET_WEBRTC_READY:
  63. return {
  64. ...state,
  65. webRTCReady: action.webRTCReady
  66. };
  67. default:
  68. return state;
  69. }
  70. });
  71. /**
  72. * Reduces a specific Redux action SET_CONFIG of the feature
  73. * base/lib-jitsi-meet.
  74. *
  75. * @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
  76. * @param {Action} action - The Redux action SET_CONFIG to reduce.
  77. * @private
  78. * @returns {Object} The new state of the feature base/lib-jitsi-meet after the
  79. * reduction of the specified action.
  80. */
  81. function _setConfig(state, action) {
  82. return {
  83. ...state,
  84. config: {
  85. ...action.config,
  86. // The config of INITIAL_STATE is meant to override the config
  87. // downloaded from the Jitsi Meet deployment because the former
  88. // contains values that are mandatory.
  89. ...INITIAL_STATE.config
  90. }
  91. };
  92. }