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.

actions.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* @flow */
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import type { Dispatch } from 'redux';
  4. import { isOnline } from '../net-info/selectors';
  5. import JitsiMeetJS from './_';
  6. import {
  7. LIB_DID_DISPOSE,
  8. LIB_DID_INIT,
  9. LIB_INIT_ERROR,
  10. LIB_WILL_DISPOSE,
  11. LIB_WILL_INIT
  12. } from './actionTypes';
  13. import { isAnalyticsEnabled } from './functions';
  14. declare var APP: Object;
  15. /**
  16. * Disposes (of) lib-jitsi-meet.
  17. *
  18. * @returns {Function}
  19. */
  20. export function disposeLib() {
  21. return (dispatch: Dispatch<any>) => {
  22. dispatch({ type: LIB_WILL_DISPOSE });
  23. // TODO Currently, lib-jitsi-meet doesn't have the functionality to
  24. // dispose itself.
  25. dispatch({ type: LIB_DID_DISPOSE });
  26. };
  27. }
  28. /**
  29. * Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
  30. * current config(uration).
  31. *
  32. * @returns {Function}
  33. */
  34. export function initLib() {
  35. return (dispatch: Dispatch<any>, getState: Function): void => {
  36. const state = getState();
  37. const config = state['features/base/config'];
  38. const { enableHdAudio } = config;
  39. if (!config) {
  40. throw new Error('Cannot init lib-jitsi-meet without config');
  41. }
  42. if (enableHdAudio) {
  43. Object.assign(config, {
  44. ...config,
  45. channelCount: 2,
  46. disableAP: true,
  47. enableNoAudioDetection: false,
  48. enableNoisyMicDetection: false,
  49. enableTalkWhileMuted: false,
  50. opusMaxAverageBitrate: 510000,
  51. stereo: true
  52. });
  53. }
  54. dispatch({ type: LIB_WILL_INIT });
  55. try {
  56. JitsiMeetJS.init({
  57. enableAnalyticsLogging: isAnalyticsEnabled(getState),
  58. ...config,
  59. externalStorage: jitsiLocalStorage.isLocalStorageDisabled() ? jitsiLocalStorage : undefined
  60. });
  61. JitsiMeetJS.setNetworkInfo({
  62. isOnline: isOnline(state)
  63. });
  64. dispatch({ type: LIB_DID_INIT });
  65. } catch (error) {
  66. dispatch(libInitError(error));
  67. }
  68. };
  69. }
  70. /**
  71. * Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
  72. *
  73. * @param {Error} error - The Error raised by JitsiMeetJS.init().
  74. * @returns {{
  75. * type: LIB_INIT_ERROR,
  76. * error: Error
  77. * }}
  78. */
  79. export function libInitError(error: Error) {
  80. return {
  81. type: LIB_INIT_ERROR,
  82. error
  83. };
  84. }