Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import i18next from 'i18next';
  2. import { IReduxState, IStore } from '../app/types';
  3. import { IStateful } from '../base/app/types';
  4. import { getSoundFileSrc } from '../base/media/functions';
  5. import { getParticipantById, getParticipantCount, getParticipantCountWithFake } from '../base/participants/functions';
  6. import { toState } from '../base/redux/functions';
  7. import { registerSound, unregisterSound } from '../base/sounds/actions';
  8. import {
  9. E2EE_OFF_SOUND_ID,
  10. E2EE_ON_SOUND_ID,
  11. MAX_MODE_LIMIT,
  12. MAX_MODE_THRESHOLD
  13. } from './constants';
  14. import {
  15. E2EE_OFF_SOUND_FILE,
  16. E2EE_ON_SOUND_FILE
  17. } from './sounds';
  18. /**
  19. * Gets the value of a specific React {@code Component} prop of the currently
  20. * mounted {@link App}.
  21. *
  22. * @param {IStateful} stateful - The redux store or {@code getState}
  23. * function.
  24. * @param {string} propName - The name of the React {@code Component} prop of
  25. * the currently mounted {@code App} to get.
  26. * @returns {*} The value of the specified React {@code Component} prop of the
  27. * currently mounted {@code App}.
  28. */
  29. export function doesEveryoneSupportE2EE(stateful: IStateful) {
  30. const state = toState(stateful);
  31. const { numberOfParticipantsNotSupportingE2EE } = state['features/base/participants'];
  32. const { e2eeSupported } = state['features/base/conference'];
  33. const participantCount = getParticipantCountWithFake(state);
  34. if (participantCount === 1) {
  35. // This will happen if we are alone.
  36. return e2eeSupported;
  37. }
  38. return numberOfParticipantsNotSupportingE2EE === 0;
  39. }
  40. /**
  41. * Returns true is the number of participants is larger than {@code MAX_MODE_LIMIT}.
  42. *
  43. * @param {Function|Object} stateful - The redux store or {@code getState}
  44. * function.
  45. * @returns {boolean}
  46. */
  47. export function isMaxModeReached(stateful: IStateful) {
  48. const participantCount = getParticipantCount(toState(stateful));
  49. return participantCount >= MAX_MODE_LIMIT;
  50. }
  51. /**
  52. * Returns true is the number of participants is larger than {@code MAX_MODE_LIMIT + MAX_MODE_THREHOLD}.
  53. *
  54. * @param {Function|Object} stateful - The redux store or {@code getState}
  55. * function.
  56. * @returns {boolean}
  57. */
  58. export function isMaxModeThresholdReached(stateful: IStateful) {
  59. const participantCount = getParticipantCount(toState(stateful));
  60. return participantCount >= MAX_MODE_LIMIT + MAX_MODE_THRESHOLD;
  61. }
  62. /**
  63. * Returns whether e2ee is enabled by the backend.
  64. *
  65. * @param {Object} state - The redux state.
  66. * @param {string} pId - The participant id.
  67. * @returns {boolean}
  68. */
  69. export function displayVerification(state: IReduxState, pId: string) {
  70. const { conference } = state['features/base/conference'];
  71. const participant = getParticipantById(state, pId);
  72. return Boolean(conference?.isE2EEEnabled()
  73. && participant?.e2eeVerificationAvailable
  74. && participant?.e2eeVerified === undefined);
  75. }
  76. /**
  77. * Unregisters the audio files based on locale.
  78. *
  79. * @param {Dispatch<any>} dispatch - The redux dispatch function.
  80. * @returns {void}
  81. */
  82. export function unregisterE2eeAudioFiles(dispatch: IStore['dispatch']) {
  83. dispatch(unregisterSound(E2EE_OFF_SOUND_ID));
  84. dispatch(unregisterSound(E2EE_ON_SOUND_ID));
  85. }
  86. /**
  87. * Registers the audio files based on locale.
  88. *
  89. * @param {Dispatch<any>} dispatch - The redux dispatch function.
  90. * @param {boolean|undefined} shouldUnregister - Whether the sounds should be unregistered.
  91. * @returns {void}
  92. */
  93. export function registerE2eeAudioFiles(dispatch: IStore['dispatch'], shouldUnregister?: boolean) {
  94. const language = i18next.language;
  95. shouldUnregister && unregisterE2eeAudioFiles(dispatch);
  96. dispatch(registerSound(
  97. E2EE_OFF_SOUND_ID,
  98. getSoundFileSrc(E2EE_OFF_SOUND_FILE, language)));
  99. dispatch(registerSound(
  100. E2EE_ON_SOUND_ID,
  101. getSoundFileSrc(E2EE_ON_SOUND_FILE, language)));
  102. }