Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

functions.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @flow
  2. import { MEDIA_TYPE, type MediaType } from '../base/media/constants';
  3. import { isLocalParticipantModerator } from '../base/participants/functions';
  4. import { MEDIA_TYPE_TO_WHITELIST_STORE_KEY, MEDIA_TYPE_TO_PENDING_STORE_KEY } from './constants';
  5. /**
  6. * Returns this feature's root state.
  7. *
  8. * @param {Object} state - Global state.
  9. * @returns {Object} Feature state.
  10. */
  11. const getState = state => state['features/av-moderation'];
  12. /**
  13. * We use to construct once the empty array so we can keep the same instance between calls
  14. * of getParticipantsAskingToAudioUnmute.
  15. *
  16. * @type {*[]}
  17. */
  18. const EMPTY_ARRAY = [];
  19. /**
  20. * Returns whether moderation is enabled per media type.
  21. *
  22. * @param {MEDIA_TYPE} mediaType - The media type to check.
  23. * @param {Object} state - Global state.
  24. * @returns {null|boolean|*}
  25. */
  26. export const isEnabledFromState = (mediaType: MediaType, state: Object) =>
  27. (mediaType === MEDIA_TYPE.AUDIO
  28. ? getState(state)?.audioModerationEnabled
  29. : getState(state)?.videoModerationEnabled) === true;
  30. /**
  31. * Returns whether moderation is enabled per media type.
  32. *
  33. * @param {MEDIA_TYPE} mediaType - The media type to check.
  34. * @returns {null|boolean|*}
  35. */
  36. export const isEnabled = (mediaType: MediaType) => (state: Object) => isEnabledFromState(mediaType, state);
  37. /**
  38. * Returns whether moderation is supported by the backend.
  39. *
  40. * @returns {null|boolean}
  41. */
  42. export const isSupported = () => (state: Object) => {
  43. const { conference } = state['features/base/conference'];
  44. return conference ? conference.isAVModerationSupported() : false;
  45. };
  46. /**
  47. * Returns whether local participant is approved to unmute a media type.
  48. *
  49. * @param {MEDIA_TYPE} mediaType - The media type to check.
  50. * @param {Object} state - Global state.
  51. * @returns {boolean}
  52. */
  53. export const isLocalParticipantApprovedFromState = (mediaType: MediaType, state: Object) => {
  54. const approved = (mediaType === MEDIA_TYPE.AUDIO
  55. ? getState(state).audioUnmuteApproved
  56. : getState(state).videoUnmuteApproved) === true;
  57. return approved || isLocalParticipantModerator(state);
  58. };
  59. /**
  60. * Returns whether local participant is approved to unmute a media type.
  61. *
  62. * @param {MEDIA_TYPE} mediaType - The media type to check.
  63. * @returns {null|boolean|*}
  64. */
  65. export const isLocalParticipantApproved = (mediaType: MediaType) =>
  66. (state: Object) =>
  67. isLocalParticipantApprovedFromState(mediaType, state);
  68. /**
  69. * Returns a selector creator which determines if the participant is approved or not for a media type.
  70. *
  71. * @param {string} id - The participant id.
  72. * @param {MEDIA_TYPE} mediaType - The media type to check.
  73. * @returns {boolean}
  74. */
  75. export const isParticipantApproved = (id: string, mediaType: MediaType) => (state: Object) => {
  76. const storeKey = MEDIA_TYPE_TO_WHITELIST_STORE_KEY[mediaType];
  77. return Boolean(getState(state)[storeKey][id]);
  78. };
  79. /**
  80. * Returns a selector creator which determines if the participant is pending or not for a media type.
  81. *
  82. * @param {Participant} participant - The participant.
  83. * @param {MEDIA_TYPE} mediaType - The media type to check.
  84. * @returns {boolean}
  85. */
  86. export const isParticipantPending = (participant: Object, mediaType: MediaType) => (state: Object) => {
  87. const storeKey = MEDIA_TYPE_TO_PENDING_STORE_KEY[mediaType];
  88. const arr = getState(state)[storeKey];
  89. return Boolean(arr.find(pending => pending.id === participant.id));
  90. };
  91. /**
  92. * Selector which returns a list with all the participants asking to audio unmute.
  93. * This is visible ony for the moderator.
  94. *
  95. * @param {Object} state - The global state.
  96. * @returns {Array<Object>}
  97. */
  98. export const getParticipantsAskingToAudioUnmute = (state: Object) => {
  99. if (isLocalParticipantModerator(state)) {
  100. return getState(state).pendingAudio;
  101. }
  102. return EMPTY_ARRAY;
  103. };
  104. /**
  105. * Returns true if a special notification can be displayed when a participant
  106. * tries to unmute.
  107. *
  108. * @param {MediaType} mediaType - 'audio' or 'video' media type.
  109. * @param {Object} state - The global state.
  110. * @returns {boolean}
  111. */
  112. export const shouldShowModeratedNotification = (mediaType: MediaType, state: Object) =>
  113. isEnabledFromState(mediaType, state)
  114. && !isLocalParticipantApprovedFromState(mediaType, state);