2018-03-07 00:28:19 +00:00
|
|
|
// @flow
|
2017-02-03 18:51:12 +00:00
|
|
|
|
2021-12-08 21:20:26 +00:00
|
|
|
import { batch } from 'react-redux';
|
|
|
|
|
2022-04-28 08:34:23 +00:00
|
|
|
import { _RESET_BREAKOUT_ROOMS } from '../../breakout-rooms/actionTypes';
|
2022-08-04 09:41:02 +00:00
|
|
|
import { hideNotification } from '../../notifications';
|
2020-06-19 07:03:26 +00:00
|
|
|
import { isPrejoinPageVisible } from '../../prejoin/functions';
|
2021-12-08 21:20:26 +00:00
|
|
|
import { getCurrentConference } from '../conference/functions';
|
2022-04-29 14:32:16 +00:00
|
|
|
import { getMultipleVideoSendingSupportFeatureFlag } from '../config';
|
2020-06-19 07:03:26 +00:00
|
|
|
import { getAvailableDevices } from '../devices/actions';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
2017-04-05 09:03:16 +00:00
|
|
|
CAMERA_FACING_MODE,
|
2016-10-05 14:36:59 +00:00
|
|
|
MEDIA_TYPE,
|
2017-01-11 18:14:00 +00:00
|
|
|
SET_AUDIO_MUTED,
|
|
|
|
SET_CAMERA_FACING_MODE,
|
|
|
|
SET_VIDEO_MUTED,
|
2019-11-26 10:57:03 +00:00
|
|
|
VIDEO_MUTISM_AUTHORITY,
|
2017-07-18 21:41:39 +00:00
|
|
|
TOGGLE_CAMERA_FACING_MODE,
|
2021-09-10 11:05:16 +00:00
|
|
|
toggleCameraFacingMode,
|
2022-03-15 17:24:49 +00:00
|
|
|
SET_SCREENSHARE_MUTED,
|
|
|
|
VIDEO_TYPE,
|
|
|
|
setScreenshareMuted,
|
|
|
|
SCREENSHARE_MUTISM_AUTHORITY
|
2016-10-05 14:36:59 +00:00
|
|
|
} from '../media';
|
2021-12-08 21:20:26 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
import {
|
2022-03-15 17:24:49 +00:00
|
|
|
TRACK_ADDED,
|
|
|
|
TRACK_MUTE_UNMUTE_FAILED,
|
2019-06-12 21:05:41 +00:00
|
|
|
TRACK_NO_DATA_FROM_SOURCE,
|
|
|
|
TRACK_REMOVED,
|
2022-03-15 17:24:49 +00:00
|
|
|
TRACK_STOPPED,
|
2018-03-07 00:28:19 +00:00
|
|
|
TRACK_UPDATED
|
|
|
|
} from './actionTypes';
|
2020-05-20 10:57:03 +00:00
|
|
|
import {
|
|
|
|
createLocalTracksA,
|
2021-12-10 10:50:12 +00:00
|
|
|
destroyLocalTracks,
|
2020-05-20 10:57:03 +00:00
|
|
|
showNoDataFromSourceVideoError,
|
2021-09-10 11:05:16 +00:00
|
|
|
toggleScreensharing,
|
2022-03-15 17:24:49 +00:00
|
|
|
trackMuteUnmuteFailed,
|
2021-12-08 21:20:26 +00:00
|
|
|
trackRemoved,
|
2020-05-20 10:57:03 +00:00
|
|
|
trackNoDataFromSourceNotificationInfoChanged
|
|
|
|
} from './actions';
|
2019-07-10 11:02:27 +00:00
|
|
|
import {
|
|
|
|
getLocalTrack,
|
|
|
|
getTrackByJitsiTrack,
|
|
|
|
isUserInteractionRequiredForUnmute,
|
|
|
|
setTrackMuted
|
|
|
|
} from './functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-01-12 09:13:20 +00:00
|
|
|
import './subscriber';
|
|
|
|
|
2017-06-20 16:30:54 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-02-27 22:45:53 +00:00
|
|
|
* Middleware that captures LIB_DID_DISPOSE and LIB_DID_INIT actions and,
|
|
|
|
* respectively, creates/destroys local media tracks. Also listens to
|
|
|
|
* media-related actions and performs corresponding operations with tracks.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-31 16:27:34 +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) {
|
2020-06-19 07:03:26 +00:00
|
|
|
case TRACK_ADDED: {
|
2022-04-29 14:32:16 +00:00
|
|
|
const { local } = action.track;
|
2022-04-07 15:16:27 +00:00
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
// The devices list needs to be refreshed when no initial video permissions
|
|
|
|
// were granted and a local video track is added by umuting the video.
|
2022-04-07 15:16:27 +00:00
|
|
|
if (local) {
|
2020-06-19 07:03:26 +00:00
|
|
|
store.dispatch(getAvailableDevices());
|
|
|
|
}
|
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
break;
|
2020-06-19 07:03:26 +00:00
|
|
|
}
|
2019-06-12 21:05:41 +00:00
|
|
|
case TRACK_NO_DATA_FROM_SOURCE: {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
_handleNoDataFromSourceErrors(store, action);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2019-06-12 21:05:41 +00:00
|
|
|
case TRACK_REMOVED: {
|
|
|
|
_removeNoDataFromSourceNotification(store, action.track);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-11 18:14:00 +00:00
|
|
|
case SET_AUDIO_MUTED:
|
2019-07-10 11:02:27 +00:00
|
|
|
if (!action.muted
|
|
|
|
&& isUserInteractionRequiredForUnmute(store.getState())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:14:00 +00:00
|
|
|
_setMuted(store, action, MEDIA_TYPE.AUDIO);
|
2016-10-05 14:36:59 +00:00
|
|
|
break;
|
|
|
|
|
2017-02-22 09:25:58 +00:00
|
|
|
case SET_CAMERA_FACING_MODE: {
|
2017-07-18 21:41:39 +00:00
|
|
|
// XXX The camera facing mode of a MediaStreamTrack can be specified
|
|
|
|
// only at initialization time and then it can only be toggled. So in
|
|
|
|
// order to set the camera facing mode, one may destroy the track and
|
|
|
|
// then initialize a new instance with the new camera facing mode. But
|
|
|
|
// that is inefficient on mobile at least so the following relies on the
|
|
|
|
// fact that there are 2 camera facing modes and merely toggles between
|
|
|
|
// them to (hopefully) get the camera in the specified state.
|
2017-02-22 09:25:58 +00:00
|
|
|
const localTrack = _getLocalTrack(store, MEDIA_TYPE.VIDEO);
|
2017-07-18 21:41:39 +00:00
|
|
|
let jitsiTrack;
|
2017-02-22 09:25:58 +00:00
|
|
|
|
2017-07-18 21:41:39 +00:00
|
|
|
if (localTrack
|
|
|
|
&& (jitsiTrack = localTrack.jitsiTrack)
|
|
|
|
&& jitsiTrack.getCameraFacingMode()
|
|
|
|
!== action.cameraFacingMode) {
|
|
|
|
store.dispatch(toggleCameraFacingMode());
|
2017-02-22 09:25:58 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
break;
|
2017-02-22 09:25:58 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
case SET_SCREENSHARE_MUTED:
|
|
|
|
_setMuted(store, action, action.mediaType);
|
|
|
|
break;
|
|
|
|
|
2017-01-17 14:32:20 +00:00
|
|
|
case SET_VIDEO_MUTED:
|
2019-07-10 11:02:27 +00:00
|
|
|
if (!action.muted
|
|
|
|
&& isUserInteractionRequiredForUnmute(store.getState())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
_setMuted(store, action, action.mediaType);
|
2016-10-05 14:36:59 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-03 08:57:01 +00:00
|
|
|
case TOGGLE_CAMERA_FACING_MODE: {
|
|
|
|
const localTrack = _getLocalTrack(store, MEDIA_TYPE.VIDEO);
|
|
|
|
let jitsiTrack;
|
2017-04-05 09:03:16 +00:00
|
|
|
|
|
|
|
if (localTrack && (jitsiTrack = localTrack.jitsiTrack)) {
|
|
|
|
// XXX MediaStreamTrack._switchCamera is a custom function
|
|
|
|
// implemented in react-native-webrtc for video which switches
|
|
|
|
// between the cameras via a native WebRTC library implementation
|
|
|
|
// without making any changes to the track.
|
|
|
|
jitsiTrack._switchCamera();
|
2017-04-03 08:57:01 +00:00
|
|
|
|
|
|
|
// Don't mirror the video of the back/environment-facing camera.
|
2017-04-05 09:03:16 +00:00
|
|
|
const mirror
|
|
|
|
= jitsiTrack.getCameraFacingMode() === CAMERA_FACING_MODE.USER;
|
|
|
|
|
2017-04-03 08:57:01 +00:00
|
|
|
store.dispatch({
|
|
|
|
type: TRACK_UPDATED,
|
|
|
|
track: {
|
|
|
|
jitsiTrack,
|
2017-04-05 09:03:16 +00:00
|
|
|
mirror
|
2017-04-03 08:57:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
case TRACK_MUTE_UNMUTE_FAILED: {
|
|
|
|
const { jitsiTrack } = action.track;
|
|
|
|
const muted = action.wasMuted;
|
|
|
|
const isVideoTrack = jitsiTrack.getType() !== MEDIA_TYPE.AUDIO;
|
|
|
|
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
if (isVideoTrack && jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP
|
2022-04-29 14:32:16 +00:00
|
|
|
&& getMultipleVideoSendingSupportFeatureFlag(store.getState())) {
|
2022-03-15 17:24:49 +00:00
|
|
|
store.dispatch(setScreenshareMuted(!muted));
|
|
|
|
} else if (isVideoTrack) {
|
|
|
|
APP.conference.setVideoMuteStatus();
|
|
|
|
} else {
|
|
|
|
APP.conference.setAudioMuteStatus(!muted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TRACK_STOPPED: {
|
|
|
|
const { jitsiTrack } = action.track;
|
|
|
|
|
|
|
|
if (typeof APP !== 'undefined'
|
2022-04-29 14:32:16 +00:00
|
|
|
&& getMultipleVideoSendingSupportFeatureFlag(store.getState())
|
2022-03-15 17:24:49 +00:00
|
|
|
&& jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP) {
|
|
|
|
store.dispatch(toggleScreensharing(false));
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-03-15 17:24:49 +00:00
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2021-10-27 09:37:23 +00:00
|
|
|
case TRACK_UPDATED: {
|
2017-08-04 21:06:42 +00:00
|
|
|
// TODO Remove the following calls to APP.UI once components interested
|
|
|
|
// in track mute changes are moved into React and/or redux.
|
2017-06-20 20:09:34 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
2020-04-14 22:41:30 +00:00
|
|
|
const result = next(action);
|
2022-03-15 17:24:49 +00:00
|
|
|
const state = store.getState();
|
2020-04-14 22:41:30 +00:00
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
if (isPrejoinPageVisible(state)) {
|
2020-06-29 07:45:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-20 16:30:54 +00:00
|
|
|
const { jitsiTrack } = action.track;
|
2017-08-04 21:06:42 +00:00
|
|
|
const muted = jitsiTrack.isMuted();
|
2017-06-20 16:30:54 +00:00
|
|
|
const participantID = jitsiTrack.getParticipantId();
|
2019-11-26 10:57:03 +00:00
|
|
|
const isVideoTrack = jitsiTrack.type !== MEDIA_TYPE.AUDIO;
|
2017-06-20 20:09:34 +00:00
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
if (isVideoTrack) {
|
2020-09-29 00:34:37 +00:00
|
|
|
// Do not change the video mute state for local presenter tracks.
|
2019-12-04 20:28:42 +00:00
|
|
|
if (jitsiTrack.type === MEDIA_TYPE.PRESENTER) {
|
|
|
|
APP.conference.mutePresenter(muted);
|
2022-03-15 17:24:49 +00:00
|
|
|
} else if (jitsiTrack.isLocal() && !(jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP)) {
|
2021-05-04 12:57:34 +00:00
|
|
|
APP.conference.setVideoMuteStatus();
|
2022-03-15 17:24:49 +00:00
|
|
|
} else if (jitsiTrack.isLocal() && muted && jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP) {
|
2022-04-29 14:32:16 +00:00
|
|
|
!getMultipleVideoSendingSupportFeatureFlag(state)
|
2022-03-15 17:24:49 +00:00
|
|
|
&& store.dispatch(toggleScreensharing(false, false, true));
|
2017-06-20 20:09:34 +00:00
|
|
|
} else {
|
2020-10-23 22:48:56 +00:00
|
|
|
APP.UI.setVideoMuted(participantID);
|
2017-06-20 20:09:34 +00:00
|
|
|
}
|
2017-08-18 11:30:30 +00:00
|
|
|
} else if (jitsiTrack.isLocal()) {
|
|
|
|
APP.conference.setAudioMuteStatus(muted);
|
2017-06-20 16:30:54 +00:00
|
|
|
} else {
|
2017-08-04 21:06:42 +00:00
|
|
|
APP.UI.setAudioMuted(participantID, muted);
|
2017-06-20 16:30:54 +00:00
|
|
|
}
|
2020-04-14 22:41:30 +00:00
|
|
|
|
|
|
|
return result;
|
2017-06-20 16:30:54 +00:00
|
|
|
}
|
2021-10-27 09:37:23 +00:00
|
|
|
const { jitsiTrack } = action.track;
|
2017-06-20 16:30:54 +00:00
|
|
|
|
2021-10-27 09:37:23 +00:00
|
|
|
if (jitsiTrack.isMuted()
|
|
|
|
&& jitsiTrack.type === MEDIA_TYPE.VIDEO && jitsiTrack.videoType === VIDEO_TYPE.DESKTOP) {
|
|
|
|
store.dispatch(toggleScreensharing(false));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
2021-12-08 21:20:26 +00:00
|
|
|
/**
|
|
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
2021-12-09 17:46:27 +00:00
|
|
|
* is left or failed, remove all tracks from the store.
|
2021-12-08 21:20:26 +00:00
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => getCurrentConference(state),
|
|
|
|
(conference, { dispatch, getState }, prevConference) => {
|
2022-04-14 19:35:41 +00:00
|
|
|
const { authRequired, error } = getState()['features/base/conference'];
|
2021-12-23 17:57:05 +00:00
|
|
|
|
|
|
|
// conference keep flipping while we are authenticating, skip clearing while we are in that process
|
2022-04-14 19:35:41 +00:00
|
|
|
if (prevConference && !conference && !authRequired && !error) {
|
2021-12-23 17:57:05 +00:00
|
|
|
|
2021-12-09 17:46:27 +00:00
|
|
|
// Clear all tracks.
|
2021-12-10 10:50:12 +00:00
|
|
|
const remoteTracks = getState()['features/base/tracks'].filter(t => !t.local);
|
2021-12-08 21:20:26 +00:00
|
|
|
|
|
|
|
batch(() => {
|
2021-12-10 10:50:12 +00:00
|
|
|
dispatch(destroyLocalTracks());
|
|
|
|
for (const track of remoteTracks) {
|
2021-12-08 21:20:26 +00:00
|
|
|
dispatch(trackRemoved(track.jitsiTrack));
|
|
|
|
}
|
2022-04-28 08:34:23 +00:00
|
|
|
dispatch({ type: _RESET_BREAKOUT_ROOMS });
|
2021-12-08 21:20:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-12 21:05:41 +00:00
|
|
|
/**
|
|
|
|
* Handles no data from source errors.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified action is
|
|
|
|
* dispatched.
|
|
|
|
* @param {Action} action - The redux action dispatched in the specified store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _handleNoDataFromSourceErrors(store, action) {
|
|
|
|
const { getState, dispatch } = store;
|
|
|
|
|
|
|
|
const track = getTrackByJitsiTrack(getState()['features/base/tracks'], action.track.jitsiTrack);
|
|
|
|
|
|
|
|
if (!track || !track.local) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { jitsiTrack } = track;
|
|
|
|
|
|
|
|
if (track.mediaType === MEDIA_TYPE.AUDIO && track.isReceivingData) {
|
|
|
|
_removeNoDataFromSourceNotification(store, action.track);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (track.mediaType === MEDIA_TYPE.VIDEO) {
|
|
|
|
const { noDataFromSourceNotificationInfo = {} } = track;
|
|
|
|
|
|
|
|
if (track.isReceivingData) {
|
|
|
|
if (noDataFromSourceNotificationInfo.timeout) {
|
|
|
|
clearTimeout(noDataFromSourceNotificationInfo.timeout);
|
|
|
|
dispatch(trackNoDataFromSourceNotificationInfoChanged(jitsiTrack, undefined));
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to remove the notification if there is one.
|
|
|
|
_removeNoDataFromSourceNotification(store, action.track);
|
|
|
|
} else {
|
|
|
|
if (noDataFromSourceNotificationInfo.timeout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeout = setTimeout(() => dispatch(showNoDataFromSourceVideoError(jitsiTrack)), 5000);
|
|
|
|
|
|
|
|
dispatch(trackNoDataFromSourceNotificationInfoChanged(jitsiTrack, { timeout }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 16:43:15 +00:00
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Gets the local track associated with a specific {@code MEDIA_TYPE} in a
|
2017-07-31 16:27:34 +00:00
|
|
|
* specific redux store.
|
2016-10-25 16:43:15 +00:00
|
|
|
*
|
2017-07-31 16:27:34 +00:00
|
|
|
* @param {Store} store - The redux store from which the local track associated
|
2017-10-01 06:35:19 +00:00
|
|
|
* with the specified {@code mediaType} is to be retrieved.
|
|
|
|
* @param {MEDIA_TYPE} mediaType - The {@code MEDIA_TYPE} of the local track to
|
|
|
|
* be retrieved from the specified {@code store}.
|
2018-04-06 20:04:25 +00:00
|
|
|
* @param {boolean} [includePending] - Indicates whether a local track is to be
|
|
|
|
* returned if it is still pending. A local track is pending if
|
|
|
|
* {@code getUserMedia} is still executing to create it and, consequently, its
|
|
|
|
* {@code jitsiTrack} property is {@code undefined}. By default a pending local
|
|
|
|
* track is not returned.
|
2016-10-25 16:43:15 +00:00
|
|
|
* @private
|
2017-10-01 06:35:19 +00:00
|
|
|
* @returns {Track} The local {@code Track} associated with the specified
|
|
|
|
* {@code mediaType} in the specified {@code store}.
|
2016-10-25 16:43:15 +00:00
|
|
|
*/
|
2018-04-06 20:04:25 +00:00
|
|
|
function _getLocalTrack(
|
|
|
|
{ getState }: { getState: Function },
|
|
|
|
mediaType: MEDIA_TYPE,
|
|
|
|
includePending: boolean = false) {
|
|
|
|
return (
|
|
|
|
getLocalTrack(
|
|
|
|
getState()['features/base/tracks'],
|
|
|
|
mediaType,
|
|
|
|
includePending));
|
2016-10-25 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 21:05:41 +00:00
|
|
|
/**
|
|
|
|
* Removes the no data from source notification associated with the JitsiTrack if displayed.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {Track} track - The redux action dispatched in the specified store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _removeNoDataFromSourceNotification({ getState, dispatch }, track) {
|
|
|
|
const t = getTrackByJitsiTrack(getState()['features/base/tracks'], track.jitsiTrack);
|
|
|
|
const { jitsiTrack, noDataFromSourceNotificationInfo = {} } = t || {};
|
|
|
|
|
|
|
|
if (noDataFromSourceNotificationInfo && noDataFromSourceNotificationInfo.uid) {
|
|
|
|
dispatch(hideNotification(noDataFromSourceNotificationInfo.uid));
|
|
|
|
dispatch(trackNoDataFromSourceNotificationInfoChanged(jitsiTrack, undefined));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Mutes or unmutes a local track with a specific media type.
|
|
|
|
*
|
2017-07-31 16:27:34 +00:00
|
|
|
* @param {Store} store - The redux store in which the specified action is
|
2016-10-05 14:36:59 +00:00
|
|
|
* dispatched.
|
2017-07-31 16:27:34 +00:00
|
|
|
* @param {Action} action - The redux action dispatched in the specified store.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {MEDIA_TYPE} mediaType - The {@link MEDIA_TYPE} of the local track
|
|
|
|
* which is being muted or unmuted.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-03-15 17:24:49 +00:00
|
|
|
async function _setMuted(store, { ensureTrack, authority, muted }, mediaType: MEDIA_TYPE) {
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const localTrack = _getLocalTrack(store, mediaType, /* includePending */ true);
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
if (mediaType === MEDIA_TYPE.SCREENSHARE
|
2022-04-29 14:32:16 +00:00
|
|
|
&& getMultipleVideoSendingSupportFeatureFlag(state)
|
2022-03-15 17:24:49 +00:00
|
|
|
&& !muted) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-08-14 13:27:24 +00:00
|
|
|
if (localTrack) {
|
2022-03-15 17:24:49 +00:00
|
|
|
// The `jitsiTrack` property will have a value only for a localTrack for which `getUserMedia` has already
|
|
|
|
// completed. If there's no `jitsiTrack`, then the `muted` state will be applied once the `jitsiTrack` is
|
|
|
|
// created.
|
2018-04-06 20:04:25 +00:00
|
|
|
const { jitsiTrack } = localTrack;
|
2022-03-15 17:24:49 +00:00
|
|
|
const isAudioOnly = (mediaType === MEDIA_TYPE.VIDEO && authority === VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY)
|
|
|
|
|| (mediaType === MEDIA_TYPE.SCREENSHARE && authority === SCREENSHARE_MUTISM_AUTHORITY.AUDIO_ONLY);
|
|
|
|
|
|
|
|
// Screenshare cannot be unmuted using the video mute button unless it is muted by audioOnly in the legacy
|
|
|
|
// screensharing mode.
|
2022-04-29 14:32:16 +00:00
|
|
|
if (jitsiTrack && (
|
|
|
|
jitsiTrack.videoType !== 'desktop' || isAudioOnly || getMultipleVideoSendingSupportFeatureFlag(state))
|
|
|
|
) {
|
2022-03-15 17:24:49 +00:00
|
|
|
setTrackMuted(jitsiTrack, muted, state).catch(() => dispatch(trackMuteUnmuteFailed(localTrack, muted)));
|
|
|
|
}
|
|
|
|
} else if (!muted && ensureTrack && (typeof APP === 'undefined' || isPrejoinPageVisible(state))) {
|
2017-08-14 13:27:24 +00:00
|
|
|
// FIXME: This only runs on mobile now because web has its own way of
|
|
|
|
// creating local tracks. Adjust the check once they are unified.
|
2022-03-15 17:24:49 +00:00
|
|
|
dispatch(createLocalTracksA({ devices: [ mediaType ] }));
|
2017-08-14 13:27:24 +00:00
|
|
|
}
|
2016-10-25 16:43:15 +00:00
|
|
|
}
|