2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-09-23 07:48:20 +00:00
|
|
|
import { IStateful } from '../app/types';
|
2022-04-29 14:32:16 +00:00
|
|
|
import {
|
|
|
|
getMultipleVideoSendingSupportFeatureFlag,
|
|
|
|
getMultipleVideoSupportFeatureFlag
|
|
|
|
} from '../config/functions.any';
|
2021-03-25 11:48:49 +00:00
|
|
|
import { isMobileBrowser } from '../environment/utils';
|
2019-07-13 13:59:58 +00:00
|
|
|
import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
|
2022-09-23 07:48:20 +00:00
|
|
|
import { setAudioMuted } from '../media/actions';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { MEDIA_TYPE, MediaType, VIDEO_TYPE } from '../media/constants';
|
2022-10-06 11:12:57 +00:00
|
|
|
import {
|
|
|
|
getParticipantByIdOrUndefined,
|
|
|
|
getVirtualScreenshareParticipantOwnerId,
|
|
|
|
isScreenShareParticipant
|
|
|
|
} from '../participants/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IParticipant } from '../participants/types';
|
2022-09-23 07:48:20 +00:00
|
|
|
import { toState } from '../redux/functions';
|
2019-05-07 08:53:01 +00:00
|
|
|
import {
|
|
|
|
getUserSelectedCameraDeviceId,
|
|
|
|
getUserSelectedMicDeviceId
|
2022-09-23 07:48:20 +00:00
|
|
|
} from '../settings/functions.any';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2022-09-23 07:48:20 +00:00
|
|
|
// @ts-ignore
|
2020-01-28 10:06:03 +00:00
|
|
|
import loadEffects from './loadEffects';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2022-09-23 07:48:20 +00:00
|
|
|
import { ITrack } from './reducer';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { ITrackOptions } from './types';
|
2017-07-18 21:41:39 +00:00
|
|
|
|
2021-04-21 13:48:05 +00:00
|
|
|
/**
|
|
|
|
* Returns root tracks state.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2021-04-21 13:48:05 +00:00
|
|
|
* @returns {Object} Tracks state.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const getTrackState = (state: IReduxState) => state['features/base/tracks'];
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Checks if the passed media type is muted for the participant.
|
2021-04-21 13:48:05 +00:00
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - Participant reference.
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {MediaType} mediaType - Media type.
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Global state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {boolean} - Is the media type muted for the participant.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isParticipantMediaMuted(participant: IParticipant, mediaType: MediaType, state: IReduxState) {
|
2021-07-09 12:36:19 +00:00
|
|
|
if (!participant) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
const tracks = getTrackState(state);
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
if (participant?.local) {
|
|
|
|
return isLocalTrackMuted(tracks, mediaType);
|
2022-10-06 11:12:57 +00:00
|
|
|
} else if (!participant?.fakeParticipant) {
|
2021-07-09 12:36:19 +00:00
|
|
|
return isRemoteTrackMuted(tracks, mediaType, participant.id);
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2021-07-09 12:36:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Checks if the participant is audio muted.
|
2021-04-21 13:48:05 +00:00
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - Participant reference.
|
|
|
|
* @param {IReduxState} state - Global state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {boolean} - Is audio muted for the participant.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isParticipantAudioMuted(participant: IParticipant, state: IReduxState) {
|
2021-07-09 12:36:19 +00:00
|
|
|
return isParticipantMediaMuted(participant, MEDIA_TYPE.AUDIO, state);
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-09 12:36:19 +00:00
|
|
|
* Checks if the participant is video muted.
|
2021-04-21 13:48:05 +00:00
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IParticipant} participant - Participant reference.
|
|
|
|
* @param {IReduxState} state - Global state.
|
2021-07-09 12:36:19 +00:00
|
|
|
* @returns {boolean} - Is video muted for the participant.
|
2021-04-21 13:48:05 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isParticipantVideoMuted(participant: IParticipant, state: IReduxState) {
|
2021-07-09 12:36:19 +00:00
|
|
|
return isParticipantMediaMuted(participant, MEDIA_TYPE.VIDEO, state);
|
|
|
|
}
|
2021-04-21 13:48:05 +00:00
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
/**
|
|
|
|
* Creates a local video track for presenter. The constraints are computed based
|
|
|
|
* on the height of the desktop that is being shared.
|
|
|
|
*
|
|
|
|
* @param {Object} options - The options with which the local presenter track
|
|
|
|
* is to be created.
|
|
|
|
* @param {string|null} [options.cameraDeviceId] - Camera device id or
|
|
|
|
* {@code undefined} to use app's settings.
|
|
|
|
* @param {number} desktopHeight - The height of the desktop that is being
|
|
|
|
* shared.
|
|
|
|
* @returns {Promise<JitsiLocalTrack>}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export async function createLocalPresenterTrack(options: ITrackOptions, desktopHeight: number) {
|
2019-11-26 10:57:03 +00:00
|
|
|
const { cameraDeviceId } = options;
|
|
|
|
|
|
|
|
// compute the constraints of the camera track based on the resolution
|
|
|
|
// of the desktop screen that is being shared.
|
2020-02-19 19:48:28 +00:00
|
|
|
const cameraHeights = [ 180, 270, 360, 540, 720 ];
|
|
|
|
const proportion = 5;
|
2019-11-26 10:57:03 +00:00
|
|
|
const result = cameraHeights.find(
|
|
|
|
height => (desktopHeight / proportion) < height);
|
|
|
|
const constraints = {
|
|
|
|
video: {
|
|
|
|
aspectRatio: 4 / 3,
|
|
|
|
height: {
|
2019-12-04 20:28:42 +00:00
|
|
|
ideal: result
|
2019-11-26 10:57:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const [ videoTrack ] = await JitsiMeetJS.createLocalTracks(
|
|
|
|
{
|
|
|
|
cameraDeviceId,
|
|
|
|
constraints,
|
|
|
|
devices: [ 'video' ]
|
|
|
|
});
|
|
|
|
|
|
|
|
videoTrack.type = MEDIA_TYPE.PRESENTER;
|
|
|
|
|
|
|
|
return videoTrack;
|
|
|
|
}
|
|
|
|
|
2017-07-18 21:41:39 +00:00
|
|
|
/**
|
|
|
|
* Create local tracks of specific types.
|
|
|
|
*
|
|
|
|
* @param {Object} options - The options with which the local tracks are to be
|
|
|
|
* created.
|
|
|
|
* @param {string|null} [options.cameraDeviceId] - Camera device id or
|
|
|
|
* {@code undefined} to use app's settings.
|
|
|
|
* @param {string[]} options.devices - Required track types such as 'audio'
|
|
|
|
* and/or 'video'.
|
|
|
|
* @param {string|null} [options.micDeviceId] - Microphone device id or
|
|
|
|
* {@code undefined} to use app's settings.
|
2021-02-02 00:20:39 +00:00
|
|
|
* @param {number|undefined} [oprions.timeout] - A timeout for JitsiMeetJS.createLocalTracks used to create the tracks.
|
2020-11-18 12:38:00 +00:00
|
|
|
* @param {boolean} [options.firePermissionPromptIsShownEvent] - Whether lib-jitsi-meet
|
2017-07-18 21:41:39 +00:00
|
|
|
* should check for a {@code getUserMedia} permission prompt and fire a
|
|
|
|
* corresponding event.
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {IStore} store - The redux store in the context of which the function
|
2017-07-18 21:41:39 +00:00
|
|
|
* is to execute and from which state such as {@code config} is to be retrieved.
|
|
|
|
* @returns {Promise<JitsiLocalTrack[]>}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function createLocalTracksF(options: ITrackOptions = {}, store?: IStore) {
|
2017-07-18 21:41:39 +00:00
|
|
|
let { cameraDeviceId, micDeviceId } = options;
|
2020-11-18 12:38:00 +00:00
|
|
|
const {
|
|
|
|
desktopSharingSourceDevice,
|
|
|
|
desktopSharingSources,
|
|
|
|
firePermissionPromptIsShownEvent,
|
|
|
|
timeout
|
|
|
|
} = options;
|
2017-07-18 21:41:39 +00:00
|
|
|
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
// TODO The app's settings should go in the redux store and then the
|
|
|
|
// reliance on the global variable APP will go away.
|
2022-09-23 07:48:20 +00:00
|
|
|
if (!store) {
|
|
|
|
store = APP.store; // eslint-disable-line no-param-reassign
|
|
|
|
}
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2019-05-07 08:53:01 +00:00
|
|
|
const state = store.getState();
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2017-07-18 21:41:39 +00:00
|
|
|
if (typeof cameraDeviceId === 'undefined' || cameraDeviceId === null) {
|
2019-05-07 08:53:01 +00:00
|
|
|
cameraDeviceId = getUserSelectedCameraDeviceId(state);
|
2017-07-18 21:41:39 +00:00
|
|
|
}
|
|
|
|
if (typeof micDeviceId === 'undefined' || micDeviceId === null) {
|
2019-05-07 08:53:01 +00:00
|
|
|
micDeviceId = getUserSelectedMicDeviceId(state);
|
2017-07-18 21:41:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 07:48:20 +00:00
|
|
|
// @ts-ignore
|
2019-07-08 10:59:23 +00:00
|
|
|
const state = store.getState();
|
2017-07-18 21:41:39 +00:00
|
|
|
const {
|
2018-02-20 21:23:41 +00:00
|
|
|
desktopSharingFrameRate,
|
2017-07-18 21:41:39 +00:00
|
|
|
firefox_fake_device, // eslint-disable-line camelcase
|
|
|
|
resolution
|
2019-07-08 10:59:23 +00:00
|
|
|
} = state['features/base/config'];
|
2020-01-28 10:06:03 +00:00
|
|
|
const constraints = options.constraints ?? state['features/base/config'].constraints;
|
2017-07-18 21:41:39 +00:00
|
|
|
|
|
|
|
return (
|
2022-09-23 07:48:20 +00:00
|
|
|
loadEffects(store).then((effectsArray: Object[]) => {
|
2019-09-19 13:28:57 +00:00
|
|
|
// Filter any undefined values returned by Promise.resolve().
|
|
|
|
const effects = effectsArray.filter(effect => Boolean(effect));
|
|
|
|
|
|
|
|
return JitsiMeetJS.createLocalTracks(
|
2019-07-08 10:59:23 +00:00
|
|
|
{
|
|
|
|
cameraDeviceId,
|
|
|
|
constraints,
|
|
|
|
desktopSharingFrameRate,
|
2021-02-02 00:20:39 +00:00
|
|
|
desktopSharingSourceDevice,
|
|
|
|
desktopSharingSources,
|
2017-07-18 21:41:39 +00:00
|
|
|
|
2019-07-08 10:59:23 +00:00
|
|
|
// Copy array to avoid mutations inside library.
|
2022-09-23 07:48:20 +00:00
|
|
|
devices: options.devices?.slice(0),
|
2019-07-08 10:59:23 +00:00
|
|
|
effects,
|
|
|
|
firefox_fake_device, // eslint-disable-line camelcase
|
2020-11-18 12:38:00 +00:00
|
|
|
firePermissionPromptIsShownEvent,
|
2019-07-08 10:59:23 +00:00
|
|
|
micDeviceId,
|
2021-02-02 00:20:39 +00:00
|
|
|
resolution,
|
|
|
|
timeout
|
2020-11-18 12:38:00 +00:00
|
|
|
})
|
2022-09-23 07:48:20 +00:00
|
|
|
.catch((err: Error) => {
|
2019-07-08 10:59:23 +00:00
|
|
|
logger.error('Failed to create local tracks', options.devices, err);
|
2017-07-18 21:41:39 +00:00
|
|
|
|
2019-07-08 10:59:23 +00:00
|
|
|
return Promise.reject(err);
|
2019-09-19 13:28:57 +00:00
|
|
|
});
|
|
|
|
}));
|
2017-07-18 21:41:39 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:45:58 +00:00
|
|
|
/**
|
|
|
|
* Returns an object containing a promise which resolves with the created tracks &
|
|
|
|
* the errors resulting from that process.
|
|
|
|
*
|
|
|
|
* @returns {Promise<JitsiLocalTrack>}
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @todo Refactor to not use APP.
|
2020-06-29 07:45:58 +00:00
|
|
|
*/
|
|
|
|
export function createPrejoinTracks() {
|
2022-09-23 07:48:20 +00:00
|
|
|
const errors: any = {};
|
2020-06-29 07:45:58 +00:00
|
|
|
const initialDevices = [ 'audio' ];
|
|
|
|
const requestedAudio = true;
|
|
|
|
let requestedVideo = false;
|
|
|
|
const { startAudioOnly, startWithAudioMuted, startWithVideoMuted } = APP.store.getState()['features/base/settings'];
|
|
|
|
|
|
|
|
// Always get a handle on the audio input device so that we have statistics even if the user joins the
|
|
|
|
// conference muted. Previous implementation would only acquire the handle when the user first unmuted,
|
|
|
|
// which would results in statistics ( such as "No audio input" or "Are you trying to speak?") being available
|
|
|
|
// only after that point.
|
|
|
|
if (startWithAudioMuted) {
|
|
|
|
APP.store.dispatch(setAudioMuted(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!startWithVideoMuted && !startAudioOnly) {
|
|
|
|
initialDevices.push('video');
|
|
|
|
requestedVideo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tryCreateLocalTracks;
|
|
|
|
|
|
|
|
if (!requestedAudio && !requestedVideo) {
|
|
|
|
// Resolve with no tracks
|
|
|
|
tryCreateLocalTracks = Promise.resolve([]);
|
|
|
|
} else {
|
2020-11-18 12:38:00 +00:00
|
|
|
tryCreateLocalTracks = createLocalTracksF({
|
|
|
|
devices: initialDevices,
|
|
|
|
firePermissionPromptIsShownEvent: true
|
2022-09-23 07:48:20 +00:00
|
|
|
}, APP.store)
|
|
|
|
.catch((err: Error) => {
|
2020-06-29 07:45:58 +00:00
|
|
|
if (requestedAudio && requestedVideo) {
|
|
|
|
|
|
|
|
// Try audio only...
|
|
|
|
errors.audioAndVideoError = err;
|
|
|
|
|
|
|
|
return (
|
2020-11-18 12:38:00 +00:00
|
|
|
createLocalTracksF({
|
|
|
|
devices: [ 'audio' ],
|
|
|
|
firePermissionPromptIsShownEvent: true
|
|
|
|
}));
|
2020-06-29 07:45:58 +00:00
|
|
|
} else if (requestedAudio && !requestedVideo) {
|
|
|
|
errors.audioOnlyError = err;
|
|
|
|
|
|
|
|
return [];
|
|
|
|
} else if (requestedVideo && !requestedAudio) {
|
|
|
|
errors.videoOnlyError = err;
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
logger.error('Should never happen');
|
|
|
|
})
|
2022-09-23 07:48:20 +00:00
|
|
|
.catch((err: Error) => {
|
2020-06-29 07:45:58 +00:00
|
|
|
// Log this just in case...
|
|
|
|
if (!requestedAudio) {
|
|
|
|
logger.error('The impossible just happened', err);
|
|
|
|
}
|
|
|
|
errors.audioOnlyError = err;
|
|
|
|
|
|
|
|
// Try video only...
|
|
|
|
return requestedVideo
|
2020-11-18 12:38:00 +00:00
|
|
|
? createLocalTracksF({
|
|
|
|
devices: [ 'video' ],
|
|
|
|
firePermissionPromptIsShownEvent: true
|
|
|
|
})
|
2020-06-29 07:45:58 +00:00
|
|
|
: [];
|
|
|
|
})
|
2022-09-23 07:48:20 +00:00
|
|
|
.catch((err: Error) => {
|
2020-06-29 07:45:58 +00:00
|
|
|
// Log this just in case...
|
|
|
|
if (!requestedVideo) {
|
|
|
|
logger.error('The impossible just happened', err);
|
|
|
|
}
|
|
|
|
errors.videoOnlyError = err;
|
|
|
|
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
tryCreateLocalTracks,
|
|
|
|
errors
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns local audio track.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalAudioTrack(tracks: ITrack[]) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return getLocalTrack(tracks, MEDIA_TYPE.AUDIO);
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the local desktop track.
|
|
|
|
*
|
|
|
|
* @param {Track[]} tracks - List of all tracks.
|
|
|
|
* @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.
|
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalDesktopTrack(tracks: ITrack[], includePending = false) {
|
2022-03-15 17:24:49 +00:00
|
|
|
return (
|
|
|
|
getLocalTracks(tracks, includePending)
|
|
|
|
.find(t => t.mediaType === MEDIA_TYPE.SCREENSHARE || t.videoType === VIDEO_TYPE.DESKTOP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the stored local desktop jitsiLocalTrack.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2022-03-15 17:24:49 +00:00
|
|
|
* @returns {JitsiLocalTrack|undefined}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getLocalJitsiDesktopTrack(state: IReduxState) {
|
2022-03-15 17:24:49 +00:00
|
|
|
const track = getLocalDesktopTrack(getTrackState(state));
|
|
|
|
|
|
|
|
return track?.jitsiTrack;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns local track by media type.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - Media type.
|
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-05 14:36:59 +00:00
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalTrack(tracks: ITrack[], mediaType: MediaType, includePending = false) {
|
2018-04-06 20:04:25 +00:00
|
|
|
return (
|
|
|
|
getLocalTracks(tracks, includePending)
|
|
|
|
.find(t => t.mediaType === mediaType));
|
2017-11-09 21:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-06 20:04:25 +00:00
|
|
|
* Returns an array containing the local tracks with or without a (valid)
|
2017-11-13 22:10:54 +00:00
|
|
|
* {@code JitsiTrack}.
|
2017-11-09 21:59:31 +00:00
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - An array containing all local tracks.
|
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.
|
2017-11-09 21:59:31 +00:00
|
|
|
* @returns {Track[]}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalTracks(tracks: ITrack[], includePending = false) {
|
2017-11-13 22:10:54 +00:00
|
|
|
// XXX A local track is considered ready only once it has its `jitsiTrack`
|
|
|
|
// property set by the `TRACK_ADDED` action. Until then there is a stub
|
|
|
|
// added just before the `getUserMedia` call with a cancellable
|
|
|
|
// `gumInProgress` property which then can be used to destroy the track that
|
|
|
|
// has not yet been added to the redux store. Once GUM is cancelled, it will
|
|
|
|
// never make it to the store nor there will be any
|
|
|
|
// `TRACK_ADDED`/`TRACK_REMOVED` actions dispatched for it.
|
2018-04-06 20:04:25 +00:00
|
|
|
return tracks.filter(t => t.local && (t.jitsiTrack || includePending));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns local video track.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalVideoTrack(tracks: ITrack[]) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return getLocalTrack(tracks, MEDIA_TYPE.VIDEO);
|
|
|
|
}
|
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the media type of the local video, presenter or video.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
2019-11-26 10:57:03 +00:00
|
|
|
* @returns {MEDIA_TYPE}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getLocalVideoType(tracks: ITrack[]) {
|
2019-11-26 10:57:03 +00:00
|
|
|
const presenterTrack = getLocalTrack(tracks, MEDIA_TYPE.PRESENTER);
|
|
|
|
|
|
|
|
return presenterTrack ? MEDIA_TYPE.PRESENTER : MEDIA_TYPE.VIDEO;
|
|
|
|
}
|
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the stored local video track.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2020-06-19 07:03:26 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getLocalJitsiVideoTrack(state: IReduxState) {
|
2021-04-21 13:48:05 +00:00
|
|
|
const track = getLocalVideoTrack(getTrackState(state));
|
2020-06-19 07:03:26 +00:00
|
|
|
|
|
|
|
return track?.jitsiTrack;
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:54:12 +00:00
|
|
|
/**
|
|
|
|
* Returns the stored local audio track.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2020-06-26 08:54:12 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getLocalJitsiAudioTrack(state: IReduxState) {
|
2021-04-21 13:48:05 +00:00
|
|
|
const track = getLocalAudioTrack(getTrackState(state));
|
2020-06-26 08:54:12 +00:00
|
|
|
|
|
|
|
return track?.jitsiTrack;
|
|
|
|
}
|
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
/**
|
|
|
|
* Returns track of specified media type for specified participant.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
|
|
|
* @param {IParticipant} participant - Participant Object.
|
2022-04-04 18:57:58 +00:00
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
|
|
|
export function getVideoTrackByParticipant(
|
2022-10-20 09:11:27 +00:00
|
|
|
state: IReduxState,
|
|
|
|
participant?: IParticipant) {
|
2022-04-04 18:57:58 +00:00
|
|
|
|
|
|
|
if (!participant) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
|
|
|
|
if (isScreenShareParticipant(participant)) {
|
2022-04-29 14:32:16 +00:00
|
|
|
return getVirtualScreenshareParticipantTrack(tracks, participant.id);
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
return getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participant.id);
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 13:42:45 +00:00
|
|
|
/**
|
|
|
|
* Returns source name for specified participant id.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The Redux state.
|
2022-05-09 13:42:45 +00:00
|
|
|
* @param {string} participantId - Participant ID.
|
|
|
|
* @returns {string | undefined}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getSourceNameByParticipantId(state: IReduxState, participantId: string) {
|
2022-05-09 13:42:45 +00:00
|
|
|
const participant = getParticipantByIdOrUndefined(state, participantId);
|
2022-10-06 11:12:57 +00:00
|
|
|
const track = getVideoTrackByParticipant(state, participant);
|
2022-05-09 13:42:45 +00:00
|
|
|
|
|
|
|
return track?.jitsiTrack?.getSourceName();
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns track of specified media type for specified participant id.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - Media type.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {string} participantId - Participant ID.
|
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
|
|
|
export function getTrackByMediaTypeAndParticipant(
|
2022-09-23 07:48:20 +00:00
|
|
|
tracks: ITrack[],
|
|
|
|
mediaType: MediaType,
|
|
|
|
participantId: string) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return tracks.find(
|
2021-02-16 22:20:44 +00:00
|
|
|
t => Boolean(t.jitsiTrack) && t.participantId === participantId && t.mediaType === mediaType
|
2016-10-05 14:36:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
/**
|
2022-04-29 14:32:16 +00:00
|
|
|
* Returns screenshare track of given virtualScreenshareParticipantId.
|
2022-04-04 18:57:58 +00:00
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
2022-04-29 14:32:16 +00:00
|
|
|
* @param {string} virtualScreenshareParticipantId - Virtual Screenshare Participant ID.
|
2022-04-04 18:57:58 +00:00
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getVirtualScreenshareParticipantTrack(tracks: ITrack[], virtualScreenshareParticipantId: string) {
|
2022-04-29 14:32:16 +00:00
|
|
|
const ownderId = getVirtualScreenshareParticipantOwnerId(virtualScreenshareParticipantId);
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
return getScreenShareTrack(tracks, ownderId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns track source names of given screen share participant ids.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The entire redux state.
|
2022-04-29 14:32:16 +00:00
|
|
|
* @param {string[]} screenShareParticipantIds - Participant ID.
|
|
|
|
* @returns {(string[])}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getRemoteScreenSharesSourceNames(state: IReduxState, screenShareParticipantIds = []) {
|
2022-04-29 14:32:16 +00:00
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
|
|
|
|
return getMultipleVideoSupportFeatureFlag(state)
|
|
|
|
? screenShareParticipantIds
|
2022-09-23 07:48:20 +00:00
|
|
|
: screenShareParticipantIds.reduce((acc: string[], id) => {
|
2022-04-29 14:32:16 +00:00
|
|
|
const sourceName = getScreenShareTrack(tracks, id)?.jitsiTrack.getSourceName();
|
|
|
|
|
|
|
|
if (sourceName) {
|
|
|
|
acc.push(sourceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns screenshare track of given owner ID.
|
|
|
|
*
|
|
|
|
* @param {Track[]} tracks - List of all tracks.
|
|
|
|
* @param {string} ownerId - Screenshare track owner ID.
|
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getScreenShareTrack(tracks: ITrack[], ownerId: string) {
|
2022-04-29 14:32:16 +00:00
|
|
|
return tracks.find(
|
|
|
|
t => Boolean(t.jitsiTrack)
|
|
|
|
&& t.participantId === ownerId
|
|
|
|
&& (t.mediaType === MEDIA_TYPE.SCREENSHARE || t.videoType === VIDEO_TYPE.DESKTOP)
|
|
|
|
);
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 17:49:36 +00:00
|
|
|
/**
|
|
|
|
* Returns track source name of specified media type for specified participant id.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - Media type.
|
2021-12-16 17:49:36 +00:00
|
|
|
* @param {string} participantId - Participant ID.
|
|
|
|
* @returns {(string|undefined)}
|
|
|
|
*/
|
|
|
|
export function getTrackSourceNameByMediaTypeAndParticipant(
|
2022-09-23 07:48:20 +00:00
|
|
|
tracks: ITrack[],
|
|
|
|
mediaType: MediaType,
|
|
|
|
participantId: string) {
|
2021-12-16 17:49:36 +00:00
|
|
|
const track = getTrackByMediaTypeAndParticipant(
|
|
|
|
tracks,
|
|
|
|
mediaType,
|
|
|
|
participantId);
|
|
|
|
|
|
|
|
return track?.jitsiTrack?.getSourceName();
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the track if any which corresponds to a specific instance
|
|
|
|
* of JitsiLocalTrack or JitsiRemoteTrack.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {(JitsiLocalTrack|JitsiRemoteTrack)} jitsiTrack - JitsiTrack instance.
|
|
|
|
* @returns {(Track|undefined)}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getTrackByJitsiTrack(tracks: ITrack[], jitsiTrack: any) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return tracks.find(t => t.jitsiTrack === jitsiTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns tracks of specified media type.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - Media type.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Track[]}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function getTracksByMediaType(tracks: ITrack[], mediaType: MediaType) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return tracks.filter(t => t.mediaType === mediaType);
|
|
|
|
}
|
2017-08-18 11:30:30 +00:00
|
|
|
|
2019-11-26 10:57:03 +00:00
|
|
|
/**
|
2020-10-26 18:05:22 +00:00
|
|
|
* Checks if the local video camera track in the given set of tracks is muted.
|
2019-11-26 10:57:03 +00:00
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @returns {ITrack[]}
|
2019-11-26 10:57:03 +00:00
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function isLocalCameraTrackMuted(tracks: ITrack[]) {
|
2019-11-26 10:57:03 +00:00
|
|
|
const presenterTrack = getLocalTrack(tracks, MEDIA_TYPE.PRESENTER);
|
|
|
|
const videoTrack = getLocalTrack(tracks, MEDIA_TYPE.VIDEO);
|
|
|
|
|
|
|
|
// Make sure we check the mute status of only camera tracks, i.e.,
|
|
|
|
// presenter track when it exists, camera track when the presenter
|
|
|
|
// track doesn't exist.
|
|
|
|
if (presenterTrack) {
|
|
|
|
return isLocalTrackMuted(tracks, MEDIA_TYPE.PRESENTER);
|
|
|
|
} else if (videoTrack) {
|
|
|
|
return videoTrack.videoType === 'camera'
|
|
|
|
? isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
/**
|
|
|
|
* Checks if the first local track in the given tracks set is muted.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - The media type of tracks to be checked.
|
2017-08-18 11:30:30 +00:00
|
|
|
* @returns {boolean} True if local track is muted or false if the track is
|
|
|
|
* unmuted or if there are no local tracks of the given media type in the given
|
|
|
|
* set of tracks.
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function isLocalTrackMuted(tracks: ITrack[], mediaType: MediaType) {
|
2017-08-18 11:30:30 +00:00
|
|
|
const track = getLocalTrack(tracks, mediaType);
|
|
|
|
|
2019-01-05 16:49:21 +00:00
|
|
|
return !track || track.muted;
|
|
|
|
}
|
|
|
|
|
2020-11-04 08:32:06 +00:00
|
|
|
/**
|
|
|
|
* Checks if the local video track is of type DESKtOP.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2020-11-04 08:32:06 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isLocalVideoTrackDesktop(state: IReduxState) {
|
2021-04-21 13:48:05 +00:00
|
|
|
const videoTrack = getLocalVideoTrack(getTrackState(state));
|
2020-11-04 08:32:06 +00:00
|
|
|
|
|
|
|
return videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-05 16:49:21 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the remote track of the given media type and the given
|
|
|
|
* participant is muted, false otherwise.
|
|
|
|
*
|
2022-09-23 07:48:20 +00:00
|
|
|
* @param {ITrack[]} tracks - List of all tracks.
|
|
|
|
* @param {MediaType} mediaType - The media type of tracks to be checked.
|
|
|
|
* @param {string} participantId - Participant ID.
|
2019-01-05 16:49:21 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function isRemoteTrackMuted(tracks: ITrack[], mediaType: MediaType, participantId: string) {
|
2019-01-05 16:49:21 +00:00
|
|
|
const track = getTrackByMediaTypeAndParticipant(
|
|
|
|
tracks, mediaType, participantId);
|
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
return !track || track.muted;
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:02:27 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not the current environment needs a user interaction with
|
|
|
|
* the page before any unmute can occur.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux state.
|
2019-07-10 11:02:27 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isUserInteractionRequiredForUnmute(state: IReduxState) {
|
2019-07-13 13:59:58 +00:00
|
|
|
return browser.isUserInteractionRequiredForUnmute()
|
2019-07-10 11:02:27 +00:00
|
|
|
&& window
|
|
|
|
&& window.self !== window.top
|
|
|
|
&& !state['features/base/user-interaction'].interacted;
|
|
|
|
}
|
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
/**
|
2022-03-15 17:24:49 +00:00
|
|
|
* Mutes or unmutes a specific {@code JitsiLocalTrack}. If the muted state of the specified {@code track} is already in
|
|
|
|
* accord with the specified {@code muted} value, then does nothing.
|
2017-08-18 11:30:30 +00:00
|
|
|
*
|
2022-03-15 17:24:49 +00:00
|
|
|
* @param {JitsiLocalTrack} track - The {@code JitsiLocalTrack} to mute or unmute.
|
|
|
|
* @param {boolean} muted - If the specified {@code track} is to be muted, then {@code true}; otherwise, {@code false}.
|
|
|
|
* @param {Object} state - The redux state.
|
2017-08-18 11:30:30 +00:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function setTrackMuted(track: any, muted: boolean, state: IReduxState) {
|
2017-08-18 11:30:30 +00:00
|
|
|
muted = Boolean(muted); // eslint-disable-line no-param-reassign
|
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
// Ignore the check for desktop track muted operation. When the screenshare is terminated by clicking on the
|
|
|
|
// browser's 'Stop sharing' button, the local stream is stopped before the inactive stream handler is fired.
|
|
|
|
// We still need to proceed here and remove the track from the peerconnection.
|
|
|
|
if (track.isMuted() === muted
|
2022-04-29 14:32:16 +00:00
|
|
|
&& !(track.getVideoType() === VIDEO_TYPE.DESKTOP && getMultipleVideoSendingSupportFeatureFlag(state))) {
|
2017-08-18 11:30:30 +00:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
const f = muted ? 'mute' : 'unmute';
|
|
|
|
|
2022-09-23 07:48:20 +00:00
|
|
|
return track[f]().catch((error: Error) => {
|
2017-11-21 13:38:53 +00:00
|
|
|
// Track might be already disposed so ignore such an error.
|
|
|
|
if (error.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
|
2018-07-30 14:38:25 +00:00
|
|
|
logger.error(`set track ${f} failed`, error);
|
2022-03-15 17:24:49 +00:00
|
|
|
|
|
|
|
return Promise.reject(error);
|
2017-11-21 13:38:53 +00:00
|
|
|
}
|
2017-08-18 11:30:30 +00:00
|
|
|
});
|
|
|
|
}
|
2021-03-25 11:48:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether toggle camera should be enabled or not.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateful - The redux store or {@code getState} function.
|
|
|
|
* @returns {boolean} - Whether toggle camera should be enabled.
|
|
|
|
*/
|
2022-09-23 07:48:20 +00:00
|
|
|
export function isToggleCameraEnabled(stateful: IStateful) {
|
2021-03-25 11:48:49 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const { videoInput } = state['features/base/devices'].availableDevices;
|
|
|
|
|
2022-09-23 07:48:20 +00:00
|
|
|
return isMobileBrowser() && Number(videoInput?.length) > 1;
|
2021-03-25 11:48:49 +00:00
|
|
|
}
|