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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* @flow */
  2. import { toState } from '../redux';
  3. import { getPropertyValue } from '../settings';
  4. import { VIDEO_MUTISM_AUTHORITY } from './constants';
  5. // XXX The configurations/preferences/settings startWithAudioMuted and startWithVideoMuted were introduced for
  6. // conferences/meetings. So it makes sense for these to not be considered outside of conferences/meetings
  7. // (e.g. WelcomePage). Later on, though, we introduced a "Video <-> Voice" toggle on the WelcomePage which utilizes
  8. // startAudioOnly outside of conferences/meetings so that particular configuration/preference/setting employs slightly
  9. // exclusive logic.
  10. const START_WITH_AUDIO_VIDEO_MUTED_SOURCES = {
  11. // We have startWithAudioMuted and startWithVideoMuted here:
  12. config: true,
  13. settings: true,
  14. // XXX We've already overwritten base/config with urlParams. However,
  15. // settings are more important than the server-side config.
  16. // Consequently, we need to read from urlParams anyway:
  17. urlParams: true,
  18. // We don't have startWithAudioMuted and startWithVideoMuted here:
  19. jwt: false
  20. };
  21. /**
  22. * Determines whether audio is currently muted.
  23. *
  24. * @param {Function|Object} stateful - The redux store, state, or
  25. * {@code getState} function.
  26. * @returns {boolean}
  27. */
  28. export function isAudioMuted(stateful: Function | Object) {
  29. return Boolean(toState(stateful)['features/base/media'].audio.muted);
  30. }
  31. /**
  32. * Determines whether video is currently muted by the audio-only authority.
  33. *
  34. * @param {Function|Object} stateful - The redux store, state, or
  35. * {@code getState} function.
  36. * @returns {boolean}
  37. */
  38. export function isVideoMutedByAudioOnly(stateful: Function | Object) {
  39. return (
  40. _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY));
  41. }
  42. /**
  43. * Determines whether video is currently muted by a specific
  44. * {@code VIDEO_MUTISM_AUTHORITY}.
  45. *
  46. * @param {Function|Object} stateful - The redux store, state, or
  47. * {@code getState} function.
  48. * @param {number} videoMutismAuthority - The {@code VIDEO_MUTISM_AUTHORITY}
  49. * which is to be checked whether it has muted video.
  50. * @returns {boolean} If video is currently muted by the specified
  51. * {@code videoMutismAuthority}, then {@code true}; otherwise, {@code false}.
  52. */
  53. function _isVideoMutedByAuthority(
  54. stateful: Function | Object,
  55. videoMutismAuthority: number) {
  56. const { muted } = toState(stateful)['features/base/media'].video;
  57. // eslint-disable-next-line no-bitwise
  58. return Boolean(muted & videoMutismAuthority);
  59. }
  60. /**
  61. * Computes the startWithAudioMuted by retrieving its values from config, URL and settings.
  62. *
  63. * @param {Object|Function} stateful - The redux state object or {@code getState} function.
  64. * @returns {boolean} - The computed startWithAudioMuted value that will be used.
  65. */
  66. export function getStartWithAudioMuted(stateful: Object | Function) {
  67. return Boolean(getPropertyValue(stateful, 'startWithAudioMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
  68. }
  69. /**
  70. * Computes the startWithVideoMuted by retrieving its values from config, URL and settings.
  71. *
  72. * @param {Object|Function} stateful - The redux state object or {@code getState} function.
  73. * @returns {boolean} - The computed startWithVideoMuted value that will be used.
  74. */
  75. export function getStartWithVideoMuted(stateful: Object | Function) {
  76. return Boolean(getPropertyValue(stateful, 'startWithVideoMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
  77. }
  78. /**
  79. * Determines whether video is currently muted by the user authority.
  80. *
  81. * @param {Function|Object} stateful - The redux store, state, or
  82. * {@code getState} function.
  83. * @returns {boolean}
  84. */
  85. export function isVideoMutedByUser(stateful: Function | Object) {
  86. return _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.USER);
  87. }
  88. /**
  89. * Determines whether a specific videoTrack should be rendered.
  90. *
  91. * @param {Track} videoTrack - The video track which is to be rendered.
  92. * @param {boolean} waitForVideoStarted - True if the specified videoTrack
  93. * should be rendered only after its associated video has started;
  94. * otherwise, false.
  95. * @returns {boolean} True if the specified videoTrack should be renderd;
  96. * otherwise, false.
  97. */
  98. export function shouldRenderVideoTrack(
  99. videoTrack: ?{ muted: boolean, videoStarted: boolean },
  100. waitForVideoStarted: boolean) {
  101. return (
  102. videoTrack
  103. && !videoTrack.muted
  104. && (!waitForVideoStarted || videoTrack.videoStarted));
  105. }