2018-04-13 16:26:42 +00:00
|
|
|
// @flow
|
2017-02-03 18:51:12 +00:00
|
|
|
|
2017-12-11 18:48:32 +00:00
|
|
|
import {
|
2018-01-03 21:24:07 +00:00
|
|
|
createStartAudioOnlyEvent,
|
|
|
|
createStartMutedConfigurationEvent,
|
|
|
|
createSyncTrackStateEvent,
|
2019-07-31 12:47:52 +00:00
|
|
|
createTrackMutedEvent,
|
2018-01-03 21:24:07 +00:00
|
|
|
sendAnalytics
|
2017-12-11 18:48:32 +00:00
|
|
|
} from '../../analytics';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { APP_STATE_CHANGED } from '../../mobile/background';
|
2021-11-30 20:08:25 +00:00
|
|
|
import {
|
|
|
|
NOTIFICATION_TIMEOUT_TYPE,
|
|
|
|
showWarningNotification
|
|
|
|
} from '../../notifications';
|
2021-09-10 11:05:16 +00:00
|
|
|
import { isForceMuted } from '../../participants-pane/functions';
|
2021-12-11 14:22:03 +00:00
|
|
|
import { isScreenMediaShared } from '../../screen-share/functions';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { SET_AUDIO_ONLY, setAudioOnly } from '../audio-only';
|
|
|
|
import { isRoomValid, SET_ROOM } from '../conference';
|
2022-04-29 14:32:16 +00:00
|
|
|
import { getMultipleVideoSendingSupportFeatureFlag } from '../config';
|
2021-09-10 11:05:16 +00:00
|
|
|
import { getLocalParticipant } from '../participants';
|
2016-10-05 14:36:59 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
2018-04-12 19:58:20 +00:00
|
|
|
import { getPropertyValue } from '../settings';
|
2021-11-23 14:06:59 +00:00
|
|
|
import {
|
|
|
|
destroyLocalTracks,
|
2021-12-07 21:48:12 +00:00
|
|
|
isLocalTrackMuted,
|
2021-11-23 14:06:59 +00:00
|
|
|
isLocalVideoTrackDesktop,
|
|
|
|
setTrackMuted,
|
|
|
|
TRACK_ADDED
|
|
|
|
} from '../tracks';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
import {
|
|
|
|
SET_AUDIO_MUTED,
|
|
|
|
SET_AUDIO_UNMUTE_PERMISSIONS,
|
2022-03-15 17:24:49 +00:00
|
|
|
SET_SCREENSHARE_MUTED,
|
2021-11-30 20:08:25 +00:00
|
|
|
SET_VIDEO_MUTED,
|
|
|
|
SET_VIDEO_UNMUTE_PERMISSIONS
|
|
|
|
} from './actionTypes';
|
2022-03-15 17:24:49 +00:00
|
|
|
import {
|
|
|
|
setAudioMuted,
|
|
|
|
setCameraFacingMode,
|
|
|
|
setScreenshareMuted,
|
|
|
|
setVideoMuted
|
|
|
|
} from './actions';
|
2019-11-26 10:57:03 +00:00
|
|
|
import {
|
|
|
|
CAMERA_FACING_MODE,
|
|
|
|
MEDIA_TYPE,
|
2022-03-15 17:24:49 +00:00
|
|
|
SCREENSHARE_MUTISM_AUTHORITY,
|
2019-11-26 10:57:03 +00:00
|
|
|
VIDEO_MUTISM_AUTHORITY
|
|
|
|
} from './constants';
|
2020-10-21 16:57:50 +00:00
|
|
|
import { getStartWithAudioMuted, getStartWithVideoMuted } from './functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2018-04-13 16:26:42 +00:00
|
|
|
import {
|
|
|
|
_AUDIO_INITIAL_MEDIA_STATE,
|
|
|
|
_VIDEO_INITIAL_MEDIA_STATE
|
|
|
|
} from './reducer';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-27 19:08:40 +00:00
|
|
|
* Implements the entry point of the middleware of the feature base/media.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2019-07-31 12:47:52 +00:00
|
|
|
case APP_STATE_CHANGED:
|
|
|
|
return _appStateChanged(store, next, action);
|
|
|
|
|
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
return _setAudioOnly(store, next, action);
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(store, next, action);
|
|
|
|
|
|
|
|
case TRACK_ADDED: {
|
|
|
|
const result = next(action);
|
2018-04-13 16:26:42 +00:00
|
|
|
const { track } = action;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
// Don't sync track mute state with the redux store for screenshare
|
|
|
|
// since video mute state represents local camera mute state only.
|
|
|
|
track.local && track.videoType !== 'desktop'
|
|
|
|
&& _syncTrackMutedState(store, track);
|
2017-07-27 19:08:40 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2021-09-10 11:05:16 +00:00
|
|
|
|
|
|
|
case SET_AUDIO_MUTED: {
|
|
|
|
const state = store.getState();
|
|
|
|
const participant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
if (!action.muted && isForceMuted(participant, MEDIA_TYPE.AUDIO, state)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
case SET_AUDIO_UNMUTE_PERMISSIONS: {
|
2022-02-17 22:25:31 +00:00
|
|
|
const { blocked, skipNotification } = action;
|
2021-12-07 21:48:12 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const isAudioMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO);
|
2021-11-30 20:08:25 +00:00
|
|
|
|
2022-02-17 22:25:31 +00:00
|
|
|
if (blocked && isAudioMuted && !skipNotification) {
|
2021-11-30 20:08:25 +00:00
|
|
|
store.dispatch(showWarningNotification({
|
|
|
|
descriptionKey: 'notify.audioUnmuteBlockedDescription',
|
|
|
|
titleKey: 'notify.audioUnmuteBlockedTitle'
|
2021-12-09 19:37:32 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2021-11-30 20:08:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
case SET_SCREENSHARE_MUTED: {
|
|
|
|
const state = store.getState();
|
|
|
|
const participant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
if (!action.muted && isForceMuted(participant, MEDIA_TYPE.SCREENSHARE, state)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-09-10 11:05:16 +00:00
|
|
|
case SET_VIDEO_MUTED: {
|
|
|
|
const state = store.getState();
|
|
|
|
const participant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
if (!action.muted && isForceMuted(participant, MEDIA_TYPE.VIDEO, state)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-11-30 20:08:25 +00:00
|
|
|
|
|
|
|
case SET_VIDEO_UNMUTE_PERMISSIONS: {
|
2022-02-17 22:25:31 +00:00
|
|
|
const { blocked, skipNotification } = action;
|
2021-12-07 21:48:12 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const isVideoMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO);
|
2021-12-10 18:44:35 +00:00
|
|
|
const isMediaShared = isScreenMediaShared(state);
|
2021-11-30 20:08:25 +00:00
|
|
|
|
2022-02-17 22:25:31 +00:00
|
|
|
if (blocked && isVideoMuted && !isMediaShared && !skipNotification) {
|
2021-11-30 20:08:25 +00:00
|
|
|
store.dispatch(showWarningNotification({
|
|
|
|
descriptionKey: 'notify.videoUnmuteBlockedDescription',
|
|
|
|
titleKey: 'notify.videoUnmuteBlockedTitle'
|
2021-12-09 19:37:32 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2021-11-30 20:08:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
return next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
});
|
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
/**
|
|
|
|
* Adjusts the video muted state based on the app state.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action {@code APP_STATE_CHANGED} which is
|
|
|
|
* being dispatched in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
*/
|
2020-11-04 08:32:06 +00:00
|
|
|
function _appStateChanged({ dispatch, getState }, next, action) {
|
|
|
|
if (navigator.product === 'ReactNative') {
|
|
|
|
const { appState } = action;
|
|
|
|
const mute = appState !== 'active' && !isLocalVideoTrackDesktop(getState());
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2020-11-04 08:32:06 +00:00
|
|
|
sendAnalytics(createTrackMutedEvent('video', 'background mode', mute));
|
2019-07-31 12:47:52 +00:00
|
|
|
|
2020-11-04 08:32:06 +00:00
|
|
|
dispatch(setVideoMuted(mute, MEDIA_TYPE.VIDEO, VIDEO_MUTISM_AUTHORITY.BACKGROUND));
|
|
|
|
}
|
2019-07-31 12:47:52 +00:00
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjusts the video muted state based on the audio-only state.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action {@code SET_AUDIO_ONLY} which is
|
|
|
|
* being dispatched in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
*/
|
2022-03-15 17:24:49 +00:00
|
|
|
function _setAudioOnly({ dispatch, getState }, next, action) {
|
2019-09-13 15:22:13 +00:00
|
|
|
const { audioOnly, ensureVideoTrack } = action;
|
2022-03-15 17:24:49 +00:00
|
|
|
const state = getState();
|
2019-07-31 12:47:52 +00:00
|
|
|
|
|
|
|
sendAnalytics(createTrackMutedEvent('video', 'audio-only mode', audioOnly));
|
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
// Make sure we mute both the desktop and video tracks.
|
2020-01-24 14:25:43 +00:00
|
|
|
dispatch(setVideoMuted(audioOnly, MEDIA_TYPE.VIDEO, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY, ensureVideoTrack));
|
2022-04-29 14:32:16 +00:00
|
|
|
if (getMultipleVideoSendingSupportFeatureFlag(state)) {
|
2022-03-15 17:24:49 +00:00
|
|
|
dispatch(setScreenshareMuted(audioOnly, MEDIA_TYPE.SCREENSHARE, SCREENSHARE_MUTISM_AUTHORITY.AUDIO_ONLY));
|
|
|
|
} else if (navigator.product !== 'ReactNative') {
|
2020-01-24 14:25:43 +00:00
|
|
|
dispatch(setVideoMuted(audioOnly, MEDIA_TYPE.PRESENTER, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY, ensureVideoTrack));
|
|
|
|
}
|
2019-07-31 12:47:52 +00:00
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-07-27 19:08:40 +00:00
|
|
|
* Notifies the feature base/media that the action {@link SET_ROOM} is being
|
|
|
|
* dispatched within a specific redux {@code store}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action, {@code SET_ROOM}, which is being
|
|
|
|
* dispatched in the specified {@code store}.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2017-07-27 19:08:40 +00:00
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified {@code action}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-07-27 19:08:40 +00:00
|
|
|
function _setRoom({ dispatch, getState }, next, action) {
|
2018-04-13 16:26:42 +00:00
|
|
|
// Figure out the desires/intents i.e. the state of base/media. There are
|
|
|
|
// multiple desires/intents ordered by precedence such as server-side
|
|
|
|
// config, config overrides in the user-supplied URL, user's own app
|
|
|
|
// settings, etc.
|
2017-09-27 04:37:08 +00:00
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
const state = getState();
|
2018-04-13 16:26:42 +00:00
|
|
|
const { room } = action;
|
|
|
|
const roomIsValid = isRoomValid(room);
|
2020-10-21 16:57:50 +00:00
|
|
|
const audioMuted = roomIsValid ? getStartWithAudioMuted(state) : _AUDIO_INITIAL_MEDIA_STATE.muted;
|
|
|
|
const videoMuted = roomIsValid ? getStartWithVideoMuted(state) : _VIDEO_INITIAL_MEDIA_STATE.muted;
|
2018-04-13 16:26:42 +00:00
|
|
|
|
|
|
|
sendAnalytics(
|
|
|
|
createStartMutedConfigurationEvent('local', audioMuted, videoMuted));
|
|
|
|
logger.log(
|
|
|
|
`Start muted: ${audioMuted ? 'audio, ' : ''}${
|
|
|
|
videoMuted ? 'video' : ''}`);
|
2017-10-09 21:40:38 +00:00
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
// Unconditionally express the desires/expectations/intents of the app and
|
|
|
|
// the user i.e. the state of base/media. Eventually, practice/reality i.e.
|
|
|
|
// the state of base/tracks will or will not agree with the desires.
|
2017-10-09 21:40:38 +00:00
|
|
|
dispatch(setAudioMuted(audioMuted));
|
2017-08-04 21:06:42 +00:00
|
|
|
dispatch(setCameraFacingMode(CAMERA_FACING_MODE.USER));
|
2017-10-09 21:40:38 +00:00
|
|
|
dispatch(setVideoMuted(videoMuted));
|
2017-09-27 04:37:08 +00:00
|
|
|
|
2018-04-13 16:26:42 +00:00
|
|
|
// startAudioOnly
|
2017-09-27 04:37:08 +00:00
|
|
|
//
|
|
|
|
// FIXME Technically, the audio-only feature is owned by base/conference,
|
|
|
|
// not base/media so the following should be in base/conference.
|
|
|
|
// Practically, I presume it was easier to write the source code here
|
2018-04-13 16:26:42 +00:00
|
|
|
// because it looks like startWithAudioMuted and startWithVideoMuted.
|
|
|
|
//
|
|
|
|
// XXX After the introduction of the "Video <-> Voice" toggle on the
|
|
|
|
// WelcomePage, startAudioOnly is utilized even outside of
|
|
|
|
// conferences/meetings.
|
2020-11-06 09:11:59 +00:00
|
|
|
const audioOnly
|
|
|
|
= Boolean(
|
|
|
|
getPropertyValue(
|
|
|
|
state,
|
|
|
|
'startAudioOnly',
|
|
|
|
/* sources */ {
|
|
|
|
// FIXME Practically, base/config is (really) correct
|
|
|
|
// only if roomIsValid. At the time of this writing,
|
|
|
|
// base/config is overwritten by URL params which leaves
|
|
|
|
// base/config incorrect on the WelcomePage after
|
|
|
|
// leaving a conference which explicitly overwrites
|
|
|
|
// base/config with URL params.
|
|
|
|
config: roomIsValid,
|
|
|
|
|
|
|
|
// XXX We've already overwritten base/config with
|
|
|
|
// urlParams if roomIsValid. However, settings are more
|
|
|
|
// important than the server-side config. Consequently,
|
|
|
|
// we need to read from urlParams anyway. We also
|
|
|
|
// probably want to read from urlParams when
|
|
|
|
// !roomIsValid.
|
|
|
|
urlParams: true,
|
|
|
|
|
|
|
|
// The following don't have complications around whether
|
|
|
|
// they are defined or not:
|
|
|
|
jwt: false,
|
|
|
|
settings: true
|
|
|
|
}));
|
2017-09-08 14:03:27 +00:00
|
|
|
|
2018-04-13 16:26:42 +00:00
|
|
|
sendAnalytics(createStartAudioOnlyEvent(audioOnly));
|
|
|
|
logger.log(`Start audio only set to ${audioOnly.toString()}`);
|
|
|
|
|
2018-06-18 15:19:59 +00:00
|
|
|
dispatch(setAudioOnly(audioOnly, false));
|
2018-04-13 16:26:42 +00:00
|
|
|
|
2021-11-23 14:06:59 +00:00
|
|
|
if (!roomIsValid) {
|
|
|
|
dispatch(destroyLocalTracks());
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
return next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Syncs muted state of local media track with muted state from media state.
|
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {Track} track - The local media track.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-08-18 11:30:30 +00:00
|
|
|
function _syncTrackMutedState({ getState }, track) {
|
2017-07-31 16:27:34 +00:00
|
|
|
const state = getState()['features/base/media'];
|
2019-11-26 10:57:03 +00:00
|
|
|
const mediaType = track.mediaType === MEDIA_TYPE.PRESENTER
|
|
|
|
? MEDIA_TYPE.VIDEO : track.mediaType;
|
|
|
|
const muted = Boolean(state[mediaType].muted);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
// XXX If muted state of track when it was added is different from our media
|
|
|
|
// muted state, we need to mute track and explicitly modify 'muted' property
|
|
|
|
// on track. This is because though TRACK_ADDED action was dispatched it's
|
2017-07-27 19:08:40 +00:00
|
|
|
// not yet in redux state and JitsiTrackEvents.TRACK_MUTE_CHANGED may be
|
2016-10-05 14:36:59 +00:00
|
|
|
// fired before track gets to state.
|
|
|
|
if (track.muted !== muted) {
|
2018-01-03 21:24:07 +00:00
|
|
|
sendAnalytics(createSyncTrackStateEvent(track.mediaType, muted));
|
2022-03-15 17:24:49 +00:00
|
|
|
logger.log(`Sync ${track.mediaType} track muted state to ${muted ? 'muted' : 'unmuted'}`);
|
2018-04-13 16:26:42 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
track.muted = muted;
|
2022-03-15 17:24:49 +00:00
|
|
|
setTrackMuted(track.jitsiTrack, muted, state);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|