jiti-meet/react/features/base/lib-jitsi-meet/actions.ts

81 lines
2.0 KiB
TypeScript
Raw Normal View History

// @ts-ignore
2020-09-25 22:51:54 +00:00
import { jitsiLocalStorage } from '@jitsi/js-utils';
2017-02-16 19:57:39 +00:00
import { IStore } from '../../app/types';
2020-03-30 13:50:26 +00:00
import { isOnline } from '../net-info/selectors';
// @ts-ignore
2017-02-28 03:21:50 +00:00
import JitsiMeetJS from './_';
import {
LIB_DID_DISPOSE,
LIB_DID_INIT,
LIB_INIT_ERROR,
LIB_WILL_DISPOSE,
LIB_WILL_INIT
} from './actionTypes';
2022-09-30 09:08:03 +00:00
import { isAnalyticsEnabled } from './functions.any';
/**
* Disposes (of) lib-jitsi-meet.
*
* @returns {Function}
*/
export function disposeLib() {
return (dispatch: IStore['dispatch']) => {
dispatch({ type: LIB_WILL_DISPOSE });
// TODO Currently, lib-jitsi-meet doesn't have the functionality to
// dispose itself.
dispatch({ type: LIB_DID_DISPOSE });
};
}
/**
* Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
* current config(uration).
*
* @returns {Function}
*/
export function initLib() {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
2020-03-30 13:50:26 +00:00
const state = getState();
const config = state['features/base/config'];
if (!config) {
throw new Error('Cannot init lib-jitsi-meet without config');
}
dispatch({ type: LIB_WILL_INIT });
try {
JitsiMeetJS.init({
enableAnalyticsLogging: isAnalyticsEnabled(getState),
2020-09-25 22:51:54 +00:00
...config,
externalStorage: jitsiLocalStorage.isLocalStorageDisabled() ? jitsiLocalStorage : undefined
});
2020-03-30 13:50:26 +00:00
JitsiMeetJS.setNetworkInfo({
isOnline: isOnline(state)
});
dispatch({ type: LIB_DID_INIT });
} catch (error: any) {
dispatch(libInitError(error));
}
};
}
/**
* Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
*
* @param {Error} error - The Error raised by JitsiMeetJS.init().
* @returns {{
* type: LIB_INIT_ERROR,
* error: Error
* }}
*/
export function libInitError(error: Error) {
return {
type: LIB_INIT_ERROR,
error
};
}