2019-06-28 17:18:47 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { getLocalVideoTrack } from '../../features/base/tracks';
|
|
|
|
|
2019-07-03 15:38:25 +00:00
|
|
|
import { BLUR_DISABLED, BLUR_ENABLED } from './actionTypes';
|
|
|
|
import { getBlurEffect } from './functions';
|
2019-06-28 17:18:47 +00:00
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
|
|
|
/**
|
2019-07-03 15:38:25 +00:00
|
|
|
* Signals the local participant is switching between blurred or non blurred video.
|
2019-06-28 17:18:47 +00:00
|
|
|
*
|
2019-07-03 15:38:25 +00:00
|
|
|
* @param {boolean} enabled - If true enables video blur, false otherwise.
|
2019-06-28 17:18:47 +00:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
export function toggleBlurEffect(enabled: boolean) {
|
|
|
|
return function(dispatch: (Object) => Object, getState: () => any) {
|
2019-07-03 15:38:25 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
if (state['features/blur'].blurEnabled !== enabled) {
|
|
|
|
const { jitsiTrack } = getLocalVideoTrack(state['features/base/tracks']);
|
2019-06-28 17:18:47 +00:00
|
|
|
|
2019-07-03 15:38:25 +00:00
|
|
|
return getBlurEffect()
|
2019-06-28 17:18:47 +00:00
|
|
|
.then(blurEffectInstance =>
|
2019-07-03 15:38:25 +00:00
|
|
|
jitsiTrack.setEffect(enabled ? blurEffectInstance : undefined)
|
2019-06-28 17:18:47 +00:00
|
|
|
.then(() => {
|
|
|
|
enabled ? dispatch(blurEnabled()) : dispatch(blurDisabled());
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
enabled ? dispatch(blurDisabled()) : dispatch(blurEnabled());
|
2019-07-03 15:38:25 +00:00
|
|
|
logger.error('setEffect failed with error:', error);
|
2019-06-28 17:18:47 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.catch(error => {
|
|
|
|
dispatch(blurDisabled());
|
2019-07-03 15:38:25 +00:00
|
|
|
logger.error('getBlurEffect failed with error:', error);
|
2019-06-28 17:18:47 +00:00
|
|
|
});
|
|
|
|
}
|
2019-07-03 15:38:25 +00:00
|
|
|
|
|
|
|
return Promise.resolve();
|
2019-06-28 17:18:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-03 15:38:25 +00:00
|
|
|
* Signals the local participant that the blur has been enabled.
|
2019-06-28 17:18:47 +00:00
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: BLUR_ENABLED
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function blurEnabled() {
|
|
|
|
return {
|
|
|
|
type: BLUR_ENABLED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-03 15:38:25 +00:00
|
|
|
* Signals the local participant that the blur has been disabled.
|
2019-06-28 17:18:47 +00:00
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: BLUR_DISABLED
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function blurDisabled() {
|
|
|
|
return {
|
|
|
|
type: BLUR_DISABLED
|
|
|
|
};
|
|
|
|
}
|