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.5KB

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