jiti-meet/react/features/base/audio-only/actions.ts

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-08-04 08:51:33 +00:00
// @ts-ignore
2020-05-20 10:57:03 +00:00
import UIEvents from '../../../../service/UI/UIEvents';
import { createAudioOnlyChangedEvent } from '../../analytics/AnalyticsEvents';
import { sendAnalytics } from '../../analytics/functions';
import { IStore } from '../../app/types';
import { SET_AUDIO_ONLY } from './actionTypes';
import logger from './logger';
2022-08-04 08:51:33 +00:00
declare let APP: any;
/**
* Sets the audio-only flag for the current JitsiConference.
*
* @param {boolean} audioOnly - True if the conference should be audio only; false, otherwise.
* @returns {{
* type: SET_AUDIO_ONLY,
* audioOnly: boolean
* }}
*/
export function setAudioOnly(audioOnly: boolean) {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const { enabled: oldValue } = getState()['features/base/audio-only'];
if (oldValue !== audioOnly) {
sendAnalytics(createAudioOnlyChangedEvent(audioOnly));
logger.log(`Audio-only ${audioOnly ? 'enabled' : 'disabled'}`);
dispatch({
type: SET_AUDIO_ONLY,
audioOnly
});
if (typeof APP !== 'undefined') {
// TODO This should be a temporary solution that lasts only until video
// tracks and all ui is moved into react/redux on the web.
APP.UI.emitEvent(UIEvents.TOGGLE_AUDIO_ONLY, audioOnly);
}
}
};
}
/**
* Toggles the audio-only flag for the current JitsiConference.
*
* @returns {Function}
*/
export function toggleAudioOnly() {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const { enabled } = getState()['features/base/audio-only'];
return dispatch(setAudioOnly(!enabled));
};
}