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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { toState } from '../base/redux/functions';
  4. /**
  5. * A short string to represent the number of visitors.
  6. * Over 100 we show numbers like 0.2 K or 9.5 K.
  7. *
  8. * @param {number} visitorsCount - The number of visitors to shorten.
  9. *
  10. * @returns {string} Short string representing the number of visitors.
  11. */
  12. export function getVisitorsShortText(visitorsCount: number) {
  13. return visitorsCount > 100 ? `${Math.round(visitorsCount / 100) / 10} K` : String(visitorsCount);
  14. }
  15. /**
  16. * Selector to return a list of promotion requests from visitors.
  17. *
  18. * @param {IReduxState} state - State object.
  19. * @returns {Array<Object>}
  20. */
  21. export function getPromotionRequests(state: IReduxState) {
  22. return state['features/visitors'].promotionRequests;
  23. }
  24. /**
  25. * Whether current UI is in visitor mode.
  26. *
  27. * @param {Function|Object} stateful - The redux store or {@code getState}
  28. * function.
  29. * @returns {boolean} Whether iAmVisitor is set.
  30. */
  31. export function iAmVisitor(stateful: IStateful) {
  32. return toState(stateful)['features/visitors'].iAmVisitor;
  33. }
  34. /**
  35. * Returns the number of visitors.
  36. *
  37. * @param {Function|Object} stateful - The redux store or {@code getState}
  38. * function.
  39. * @returns {number} - The number of visitors.
  40. */
  41. export function getVisitorsCount(stateful: IStateful) {
  42. return toState(stateful)['features/visitors'].count ?? 0;
  43. }
  44. /**
  45. * Returns the number of visitors that are waiting in queue.
  46. *
  47. * @param {Function|Object} stateful - The redux store or {@code getState}
  48. * function.
  49. * @returns {number} - The number of visitors in queue.
  50. */
  51. export function getVisitorsInQueueCount(stateful: IStateful) {
  52. return toState(stateful)['features/visitors'].inQueueCount ?? 0;
  53. }
  54. /**
  55. * Whether visitor mode is supported.
  56. *
  57. * @param {Function|Object} stateful - The redux store or {@code getState}
  58. * function.
  59. * @returns {boolean} Whether visitor moder is supported.
  60. */
  61. export function isVisitorsSupported(stateful: IStateful) {
  62. return toState(stateful)['features/visitors'].supported;
  63. }
  64. /**
  65. * Whether visitor mode is live.
  66. *
  67. * @param {Function|Object} stateful - The redux store or {@code getState}
  68. * function.
  69. * @returns {boolean} Whether visitor moder is live.
  70. */
  71. export function isVisitorsLive(stateful: IStateful) {
  72. return toState(stateful)['features/base/conference'].metadata?.visitors?.live;
  73. }
  74. /**
  75. * Whether to show visitor queue screen.
  76. *
  77. * @param {Function|Object} stateful - The redux store or {@code getState}
  78. * function.
  79. * @returns {boolean} Whether current participant is visitor and is in queue.
  80. */
  81. export function showVisitorsQueue(stateful: IStateful) {
  82. return toState(stateful)['features/visitors'].inQueue;
  83. }