您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.ts 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { IReduxState, IStore } from '../../app/types';
  2. import { MEDIA_TYPE, VIDEO_TYPE } from '../media/constants';
  3. import { getParticipantById, isScreenShareParticipant } from '../participants/functions';
  4. import { getTrackByMediaTypeAndParticipant, getVideoTrackByParticipant } from '../tracks/functions';
  5. /**
  6. * Indicates whether the test mode is enabled. When it's enabled
  7. * {@link TestHint} and other components from the testing package will be
  8. * rendered in various places across the app to help with automatic testing.
  9. *
  10. * @param {IReduxState} state - The redux store state.
  11. * @returns {boolean}
  12. */
  13. export function isTestModeEnabled(state: IReduxState): boolean {
  14. const testingConfig = state['features/base/config'].testing;
  15. return Boolean(testingConfig?.testMode);
  16. }
  17. /**
  18. * Returns the video type of the remote participant's video.
  19. *
  20. * @param {IStore} store - The redux store.
  21. * @param {string} id - The participant ID for the remote video.
  22. * @returns {VIDEO_TYPE}
  23. */
  24. export function getRemoteVideoType({ getState }: IStore, id: string) {
  25. const state = getState();
  26. const participant = getParticipantById(state, id);
  27. if (isScreenShareParticipant(participant)) {
  28. return VIDEO_TYPE.DESKTOP;
  29. }
  30. return getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id)?.videoType;
  31. }
  32. /**
  33. * Returns whether the last media event received for large video indicates that the video is playing, if not muted.
  34. *
  35. * @param {IStore} store - The redux store.
  36. * @returns {boolean}
  37. */
  38. export function isLargeVideoReceived({ getState }: IStore): boolean {
  39. const state = getState();
  40. const largeVideoParticipantId = state['features/large-video'].participantId ?? '';
  41. const largeVideoParticipant = getParticipantById(state, largeVideoParticipantId ?? '');
  42. const videoTrack = getVideoTrackByParticipant(state, largeVideoParticipant);
  43. const lastMediaEvent = state['features/large-video']?.lastMediaEvent;
  44. return Boolean(videoTrack && !videoTrack.muted
  45. && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough'));
  46. }
  47. /**
  48. * Returns whether the last media event received for a remote video indicates that the video is playing, if not muted.
  49. *
  50. * @param {IStore} store - The redux store.
  51. * @param {string} id - The participant ID for the remote video.
  52. * @returns {boolean}
  53. */
  54. export function isRemoteVideoReceived({ getState }: IStore, id: string): boolean {
  55. const state = getState();
  56. const participant = getParticipantById(state, id);
  57. const videoTrack = getVideoTrackByParticipant(state, participant);
  58. const lastMediaEvent = videoTrack?.lastMediaEvent;
  59. return Boolean(videoTrack && !videoTrack.muted
  60. && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough'));
  61. }