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.ts 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { IStateful } from '../app/types';
  2. import { toState } from '../redux/functions';
  3. import { getPropertyValue } from '../settings/functions';
  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: IStateful) {
  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: IStateful) {
  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: IStateful,
  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: IStateful) {
  67. return Boolean(getPropertyValue(stateful, 'startWithAudioMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES))
  68. || Boolean(getPropertyValue(stateful, 'startSilent', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
  69. }
  70. /**
  71. * Computes the startWithVideoMuted by retrieving its values from config, URL and settings.
  72. *
  73. * @param {Object|Function} stateful - The redux state object or {@code getState} function.
  74. * @returns {boolean} - The computed startWithVideoMuted value that will be used.
  75. */
  76. export function getStartWithVideoMuted(stateful: IStateful) {
  77. return Boolean(getPropertyValue(stateful, 'startWithVideoMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
  78. }
  79. /**
  80. * Determines whether video is currently muted.
  81. *
  82. * @param {Function|Object} stateful - The redux store, state, or {@code getState} function.
  83. * @returns {boolean}
  84. */
  85. export function isVideoMuted(stateful: IStateful) {
  86. return Boolean(toState(stateful)['features/base/media'].video.muted);
  87. }
  88. /**
  89. * Determines whether video is currently muted by the user authority.
  90. *
  91. * @param {Function|Object} stateful - The redux store, state, or
  92. * {@code getState} function.
  93. * @returns {boolean}
  94. */
  95. export function isVideoMutedByUser(stateful: IStateful) {
  96. return _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.USER);
  97. }
  98. /**
  99. * Determines whether a specific videoTrack should be rendered.
  100. *
  101. * @param {Track} videoTrack - The video track which is to be rendered.
  102. * @param {boolean} waitForVideoStarted - True if the specified videoTrack
  103. * should be rendered only after its associated video has started;
  104. * otherwise, false.
  105. * @returns {boolean} True if the specified videoTrack should be rendered;
  106. * otherwise, false.
  107. */
  108. export function shouldRenderVideoTrack(
  109. videoTrack: { muted: boolean; videoStarted: boolean; } | undefined,
  110. waitForVideoStarted: boolean) {
  111. return (
  112. videoTrack
  113. && !videoTrack.muted
  114. && (!waitForVideoStarted || videoTrack.videoStarted));
  115. }