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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* @flow */
  2. import { toState } from '../redux';
  3. import { VIDEO_MUTISM_AUTHORITY } from './constants';
  4. /**
  5. * Determines whether video is currently muted by the audio-only authority.
  6. *
  7. * @param {Function|Object} stateful - The redux store, state, or
  8. * {@code getState} function.
  9. * @returns {boolean}
  10. */
  11. export function isVideoMutedByAudioOnly(stateful: Function | Object) {
  12. return (
  13. _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY));
  14. }
  15. /**
  16. * Determines whether video is currently muted by a specific
  17. * {@code VIDEO_MUTISM_AUTHORITY}.
  18. *
  19. * @param {Function|Object} stateful - The redux store, state, or
  20. * {@code getState} function.
  21. * @param {number} videoMutismAuthority - The {@code VIDEO_MUTISM_AUTHORITY}
  22. * which is to be checked whether it has muted video.
  23. * @returns {boolean} If video is currently muted by the specified
  24. * {@code videoMutismAuthority}, then {@code true}; otherwise, {@code false}.
  25. */
  26. function _isVideoMutedByAuthority(
  27. stateful: Function | Object,
  28. videoMutismAuthority: number) {
  29. const { muted } = toState(stateful)['features/base/media'].video;
  30. // eslint-disable-next-line no-bitwise
  31. return Boolean(muted & videoMutismAuthority);
  32. }
  33. /**
  34. * Determines whether video is currently muted by the user authority.
  35. *
  36. * @param {Function|Object} stateful - The redux store, state, or
  37. * {@code getState} function.
  38. * @returns {boolean}
  39. */
  40. export function isVideoMutedByUser(stateful: Function | Object) {
  41. return _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.USER);
  42. }
  43. /**
  44. * Determines whether a specific videoTrack should be rendered.
  45. *
  46. * @param {Track} videoTrack - The video track which is to be rendered.
  47. * @param {boolean} waitForVideoStarted - True if the specified videoTrack
  48. * should be rendered only after its associated video has started;
  49. * otherwise, false.
  50. * @returns {boolean} True if the specified videoTrack should be renderd;
  51. * otherwise, false.
  52. */
  53. export function shouldRenderVideoTrack(
  54. videoTrack: ?{ muted: boolean, videoStarted: boolean },
  55. waitForVideoStarted: boolean) {
  56. return (
  57. videoTrack
  58. && !videoTrack.muted
  59. && (!waitForVideoStarted || videoTrack.videoStarted));
  60. }