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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (!config) {
  39. throw new Error('Cannot init lib-jitsi-meet without config');
  40. }
  41. dispatch({ type: LIB_WILL_INIT });
  42. try {
  43. JitsiMeetJS.init({
  44. enableAnalyticsLogging: isAnalyticsEnabled(getState),
  45. ...config,
  46. externalStorage: jitsiLocalStorage.isLocalStorageDisabled() ? jitsiLocalStorage : undefined
  47. });
  48. JitsiMeetJS.setNetworkInfo({
  49. isOnline: isOnline(state)
  50. });
  51. dispatch({ type: LIB_DID_INIT });
  52. } catch (error) {
  53. dispatch(libInitError(error));
  54. }
  55. };
  56. }
  57. /**
  58. * Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
  59. *
  60. * @param {Error} error - The Error raised by JitsiMeetJS.init().
  61. * @returns {{
  62. * type: LIB_INIT_ERROR,
  63. * error: Error
  64. * }}
  65. */
  66. export function libInitError(error: Error) {
  67. return {
  68. type: LIB_INIT_ERROR,
  69. error
  70. };
  71. }