選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

functions.ts 3.4KB

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