You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.ts 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { IReduxState, IStore } from '../../app/types';
  2. import { isTrackStreamingStatusActive } from '../../connection-indicator/functions';
  3. import { VIDEO_CODEC } from '../../video-quality/constants';
  4. import { MEDIA_TYPE, VIDEO_TYPE } from '../media/constants';
  5. import { getParticipantById, isScreenShareParticipant } from '../participants/functions';
  6. import {
  7. getLocalVideoTrack,
  8. getTrackByMediaTypeAndParticipant,
  9. getVideoTrackByParticipant
  10. } from '../tracks/functions';
  11. /**
  12. * Indicates whether the test mode is enabled. When it's enabled
  13. * {@link TestHint} and other components from the testing package will be
  14. * rendered in various places across the app to help with automatic testing.
  15. *
  16. * @param {IReduxState} state - The redux store state.
  17. * @returns {boolean}
  18. */
  19. export function isTestModeEnabled(state: IReduxState): boolean {
  20. const testingConfig = state['features/base/config'].testing;
  21. return Boolean(testingConfig?.testMode);
  22. }
  23. /**
  24. * Returns the video type of the remote participant's video.
  25. *
  26. * @param {IStore} store - The redux store.
  27. * @param {string} id - The participant ID for the remote video.
  28. * @returns {VIDEO_TYPE}
  29. */
  30. export function getRemoteVideoType({ getState }: IStore, id: string) {
  31. const state = getState();
  32. const participant = getParticipantById(state, id);
  33. if (isScreenShareParticipant(participant)) {
  34. return VIDEO_TYPE.DESKTOP;
  35. }
  36. return getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id)?.videoType;
  37. }
  38. /**
  39. * Returns whether the last media event received for large video indicates that the video is playing, if not muted.
  40. *
  41. * @param {IStore} store - The redux store.
  42. * @returns {boolean}
  43. */
  44. export function isLargeVideoReceived({ getState }: IStore): boolean {
  45. const state = getState();
  46. const largeVideoParticipantId = state['features/large-video'].participantId ?? '';
  47. const largeVideoParticipant = getParticipantById(state, largeVideoParticipantId ?? '');
  48. const videoTrack = getVideoTrackByParticipant(state, largeVideoParticipant);
  49. return Boolean(videoTrack && !videoTrack.muted && isTrackStreamingStatusActive(videoTrack));
  50. }
  51. /**
  52. * Returns whether the local video track is encoded in AV1.
  53. *
  54. * @param {IStore} store - The redux store.
  55. * @returns {boolean}
  56. */
  57. export function isLocalCameraEncodingAv1({ getState }: IStore): boolean {
  58. const state = getState();
  59. const tracks = state['features/base/tracks'];
  60. const localtrack = getLocalVideoTrack(tracks);
  61. if (localtrack?.codec?.toLowerCase() === VIDEO_CODEC.AV1) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. /**
  67. * Returns whether the local video track is encoded in H.264.
  68. *
  69. * @param {IStore} store - The redux store.
  70. * @returns {boolean}
  71. */
  72. export function isLocalCameraEncodingH264({ getState }: IStore): boolean {
  73. const state = getState();
  74. const tracks = state['features/base/tracks'];
  75. const localtrack = getLocalVideoTrack(tracks);
  76. if (localtrack?.codec?.toLowerCase() === VIDEO_CODEC.H264) {
  77. return true;
  78. }
  79. return false;
  80. }
  81. /**
  82. * Returns whether the local video track is encoded in VP8.
  83. *
  84. * @param {IStore} store - The redux store.
  85. * @returns {boolean}
  86. */
  87. export function isLocalCameraEncodingVp8({ getState }: IStore): boolean {
  88. const state = getState();
  89. const tracks = state['features/base/tracks'];
  90. const localtrack = getLocalVideoTrack(tracks);
  91. if (localtrack?.codec?.toLowerCase() === VIDEO_CODEC.VP8) {
  92. return true;
  93. }
  94. return false;
  95. }
  96. /**
  97. * Returns whether the local video track is encoded in VP9.
  98. *
  99. * @param {IStore} store - The redux store.
  100. * @returns {boolean}
  101. */
  102. export function isLocalCameraEncodingVp9({ getState }: IStore): boolean {
  103. const state = getState();
  104. const tracks = state['features/base/tracks'];
  105. const localtrack = getLocalVideoTrack(tracks);
  106. if (localtrack?.codec?.toLowerCase() === VIDEO_CODEC.VP9) {
  107. return true;
  108. }
  109. return false;
  110. }
  111. /**
  112. * Returns whether the last media event received for a remote video indicates that the video is playing, if not muted.
  113. *
  114. * @param {IStore} store - The redux store.
  115. * @param {string} id - The participant ID for the remote video.
  116. * @returns {boolean}
  117. */
  118. export function isRemoteVideoReceived({ getState }: IStore, id: string): boolean {
  119. const state = getState();
  120. const participant = getParticipantById(state, id);
  121. const videoTrack = getVideoTrackByParticipant(state, participant);
  122. return Boolean(videoTrack && !videoTrack.muted && isTrackStreamingStatusActive(videoTrack));
  123. }