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.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @ts-expect-error
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import { IStore } from '../../app/types';
  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.any';
  14. import logger from './logger';
  15. /**
  16. * Disposes (of) lib-jitsi-meet.
  17. *
  18. * @returns {Function}
  19. */
  20. export function disposeLib() {
  21. return (dispatch: IStore['dispatch']) => {
  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: IStore['dispatch'], getState: IStore['getState']) => {
  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. logger.info(`lib-jitsi-meet version: ${JitsiMeetJS.version}`);
  52. logger.info(`User Agent: ${navigator.userAgent}`);
  53. dispatch({ type: LIB_DID_INIT });
  54. } catch (error: any) {
  55. dispatch(libInitError(error));
  56. }
  57. };
  58. }
  59. /**
  60. * Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
  61. *
  62. * @param {Error} error - The Error raised by JitsiMeetJS.init().
  63. * @returns {{
  64. * type: LIB_INIT_ERROR,
  65. * error: Error
  66. * }}
  67. */
  68. export function libInitError(error: Error) {
  69. return {
  70. type: LIB_INIT_ERROR,
  71. error
  72. };
  73. }