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.js 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @flow
  2. import { getMultipleVideoSupportFeatureFlag } from '../config';
  3. import { MEDIA_TYPE, VIDEO_TYPE } from '../media';
  4. import { getParticipantById } from '../participants';
  5. import { getTrackByMediaTypeAndParticipant, getVirtualScreenshareParticipantTrack } from '../tracks';
  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 {Object} state - The redux store state.
  12. * @returns {boolean}
  13. */
  14. export function isTestModeEnabled(state: Object): boolean {
  15. const testingConfig = state['features/base/config'].testing;
  16. return Boolean(testingConfig && testingConfig.testMode);
  17. }
  18. /**
  19. * Returns the video type of the remote participant's video.
  20. *
  21. * @param {Store} 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 }: Object, id: String): VIDEO_TYPE {
  26. const state = getState();
  27. const participant = getParticipantById(state, id);
  28. if (getMultipleVideoSupportFeatureFlag(state) && participant?.isVirtualScreenshareParticipant) {
  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 {Store} store - The redux store.
  37. * @returns {boolean}
  38. */
  39. export function isLargeVideoReceived({ getState }: Object): 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) && largeVideoParticipant?.isVirtualScreenshareParticipant) {
  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 videoTrack && !videoTrack.muted && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough');
  52. }
  53. /**
  54. * Returns whether the last media event received for a remote video indicates that the video is playing, if not muted.
  55. *
  56. * @param {Store} store - The redux store.
  57. * @param {string} id - The participant ID for the remote video.
  58. * @returns {boolean}
  59. */
  60. export function isRemoteVideoReceived({ getState }: Object, id: String): boolean {
  61. const state = getState();
  62. const tracks = state['features/base/tracks'];
  63. const participant = getParticipantById(state, id);
  64. let videoTrack;
  65. if (getMultipleVideoSupportFeatureFlag(state) && participant?.isVirtualScreenshareParticipant) {
  66. videoTrack = getVirtualScreenshareParticipantTrack(tracks, id);
  67. } else {
  68. videoTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  69. }
  70. const lastMediaEvent = videoTrack?.lastMediaEvent;
  71. return videoTrack && !videoTrack.muted && (lastMediaEvent === 'playing' || lastMediaEvent === 'canplaythrough');
  72. }