Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.ts 3.5KB

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