2022-09-19 07:40:03 +00:00
|
|
|
import { IState, IStore } from '../../app/types';
|
|
|
|
import { getMultipleVideoSupportFeatureFlag } from '../config/functions.any';
|
|
|
|
import { MEDIA_TYPE, VIDEO_TYPE } from '../media/constants';
|
2022-10-06 11:12:57 +00:00
|
|
|
import { getParticipantById, isScreenShareParticipant } from '../participants/functions';
|
2022-09-19 07:40:03 +00:00
|
|
|
// eslint-disable-next-line lines-around-comment
|
|
|
|
// @ts-ignore
|
2022-09-16 15:25:54 +00:00
|
|
|
import { getTrackByMediaTypeAndParticipant, getVirtualScreenshareParticipantTrack } from '../tracks';
|
2020-12-08 14:01:16 +00:00
|
|
|
|
2018-04-18 18:06:04 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether the test mode is enabled. When it's enabled
|
|
|
|
* {@link TestHint} and other components from the testing package will be
|
|
|
|
* rendered in various places across the app to help with automatic testing.
|
|
|
|
*
|
2022-09-19 07:40:03 +00:00
|
|
|
* @param {IState} state - The redux store state.
|
2018-04-18 18:06:04 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-19 07:40:03 +00:00
|
|
|
export function isTestModeEnabled(state: IState): boolean {
|
2018-04-18 18:06:04 +00:00
|
|
|
const testingConfig = state['features/base/config'].testing;
|
|
|
|
|
2022-09-19 07:40:03 +00:00
|
|
|
return Boolean(testingConfig?.testMode);
|
2018-04-18 18:06:04 +00:00
|
|
|
}
|
2020-12-08 14:01:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the video type of the remote participant's video.
|
|
|
|
*
|
2022-09-19 07:40:03 +00:00
|
|
|
* @param {IStore} store - The redux store.
|
2020-12-08 14:01:16 +00:00
|
|
|
* @param {string} id - The participant ID for the remote video.
|
2022-09-16 15:25:54 +00:00
|
|
|
* @returns {VIDEO_TYPE}
|
2020-12-08 14:01:16 +00:00
|
|
|
*/
|
2022-09-19 07:40:03 +00:00
|
|
|
export function getRemoteVideoType({ getState }: IStore, id: string) {
|
2022-09-16 15:25:54 +00:00
|
|
|
const state = getState();
|
|
|
|
const participant = getParticipantById(state, id);
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state) && isScreenShareParticipant(participant)) {
|
2022-09-16 15:25:54 +00:00
|
|
|
return VIDEO_TYPE.DESKTOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id)?.videoType;
|
2020-12-08 14:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the last media event received for large video indicates that the video is playing, if not muted.
|
|
|
|
*
|
2022-09-19 07:40:03 +00:00
|
|
|
* @param {IStore} store - The redux store.
|
2020-12-08 14:01:16 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-19 07:40:03 +00:00
|
|
|
export function isLargeVideoReceived({ getState }: IStore): boolean {
|
2022-09-16 15:25:54 +00:00
|
|
|
const state = getState();
|
|
|
|
const largeVideoParticipantId = state['features/large-video'].participantId;
|
2022-09-19 07:40:03 +00:00
|
|
|
const largeVideoParticipant = getParticipantById(state, largeVideoParticipantId ?? '');
|
2022-09-16 15:25:54 +00:00
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
let videoTrack;
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state) && isScreenShareParticipant(largeVideoParticipant)) {
|
2022-09-16 15:25:54 +00:00
|
|
|
videoTrack = getVirtualScreenshareParticipantTrack(tracks, largeVideoParticipantId);
|
|
|
|
} else {
|
|
|
|
videoTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideoParticipantId);
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastMediaEvent = state['features/large-video']?.lastMediaEvent;
|
2020-12-08 14:01:16 +00:00
|
|
|
|
|
|
|
return videoTrack && !videoTrack.muted && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the last media event received for a remote video indicates that the video is playing, if not muted.
|
|
|
|
*
|
2022-09-19 07:40:03 +00:00
|
|
|
* @param {IStore} store - The redux store.
|
2020-12-08 14:01:16 +00:00
|
|
|
* @param {string} id - The participant ID for the remote video.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-19 07:40:03 +00:00
|
|
|
export function isRemoteVideoReceived({ getState }: IStore, id: string): boolean {
|
2022-09-16 15:25:54 +00:00
|
|
|
const state = getState();
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const participant = getParticipantById(state, id);
|
|
|
|
let videoTrack;
|
|
|
|
|
2022-10-06 11:12:57 +00:00
|
|
|
if (getMultipleVideoSupportFeatureFlag(state) && isScreenShareParticipant(participant)) {
|
2022-09-16 15:25:54 +00:00
|
|
|
videoTrack = getVirtualScreenshareParticipantTrack(tracks, id);
|
|
|
|
} else {
|
|
|
|
videoTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
|
|
|
|
}
|
2021-02-01 16:09:12 +00:00
|
|
|
const lastMediaEvent = videoTrack?.lastMediaEvent;
|
2020-12-08 14:01:16 +00:00
|
|
|
|
2021-02-05 20:05:39 +00:00
|
|
|
return videoTrack && !videoTrack.muted && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough');
|
2020-12-08 14:01:16 +00:00
|
|
|
}
|