2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-09-19 07:40:03 +00:00
|
|
|
import { MEDIA_TYPE, VIDEO_TYPE } from '../media/constants';
|
2022-10-06 11:12:57 +00:00
|
|
|
import { getParticipantById, isScreenShareParticipant } from '../participants/functions';
|
2022-11-08 19:15:49 +00:00
|
|
|
import { getTrackByMediaTypeAndParticipant, getVideoTrackByParticipant } from '../tracks/functions';
|
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-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The redux store state.
|
2018-04-18 18:06:04 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isTestModeEnabled(state: IReduxState): 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-11-08 19:15:49 +00:00
|
|
|
if (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();
|
2022-10-11 10:47:54 +00:00
|
|
|
const largeVideoParticipantId = state['features/large-video'].participantId ?? '';
|
2022-09-19 07:40:03 +00:00
|
|
|
const largeVideoParticipant = getParticipantById(state, largeVideoParticipantId ?? '');
|
2022-11-08 19:15:49 +00:00
|
|
|
const videoTrack = getVideoTrackByParticipant(state, largeVideoParticipant);
|
2022-09-16 15:25:54 +00:00
|
|
|
const lastMediaEvent = state['features/large-video']?.lastMediaEvent;
|
2020-12-08 14:01:16 +00:00
|
|
|
|
2022-10-11 10:47:54 +00:00
|
|
|
return Boolean(videoTrack && !videoTrack.muted
|
|
|
|
&& (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough'));
|
2020-12-08 14:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 participant = getParticipantById(state, id);
|
2022-11-08 19:15:49 +00:00
|
|
|
const videoTrack = getVideoTrackByParticipant(state, participant);
|
2021-02-01 16:09:12 +00:00
|
|
|
const lastMediaEvent = videoTrack?.lastMediaEvent;
|
2020-12-08 14:01:16 +00:00
|
|
|
|
2022-10-11 10:47:54 +00:00
|
|
|
return Boolean(videoTrack && !videoTrack.muted
|
|
|
|
&& (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough'));
|
2020-12-08 14:01:16 +00:00
|
|
|
}
|