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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { IReduxState } from '../app/types';
  2. import { getCurrentConference } from '../base/conference/functions';
  3. import { getVisitorsCount } from '../visitors/functions';
  4. import { IKnockingParticipant } from './types';
  5. /**
  6. * Selector to return lobby enable state.
  7. *
  8. * @param {IReduxState} state - State object.
  9. * @returns {boolean}
  10. */
  11. export function getLobbyEnabled(state: IReduxState) {
  12. return state['features/lobby'].lobbyEnabled;
  13. }
  14. /**
  15. * Selector to return a list of knocking participants.
  16. *
  17. * @param {IReduxState} state - State object.
  18. * @returns {Array<Object>}
  19. */
  20. export function getKnockingParticipants(state: IReduxState) {
  21. return state['features/lobby'].knockingParticipants;
  22. }
  23. /**
  24. * Selector to return lobby visibility.
  25. *
  26. * @param {IReduxState} state - State object.
  27. * @returns {any}
  28. */
  29. export function getIsLobbyVisible(state: IReduxState) {
  30. return state['features/lobby'].lobbyVisible;
  31. }
  32. /**
  33. * Selector to return array with knocking participant ids.
  34. *
  35. * @param {IReduxState} state - State object.
  36. * @returns {Array}
  37. */
  38. export function getKnockingParticipantsById(state: IReduxState) {
  39. return getKnockingParticipants(state).map(participant => participant.id);
  40. }
  41. /**
  42. * Selector to return the lobby config.
  43. *
  44. * @param {IReduxState} state - State object.
  45. * @returns {Object}
  46. */
  47. export function getLobbyConfig(state: IReduxState) {
  48. return state['features/base/config']?.lobby || {};
  49. }
  50. /**
  51. * Function that handles the visibility of the lobby chat message.
  52. *
  53. * @param {Object} participant - Lobby Participant.
  54. * @returns {Function}
  55. */
  56. export function showLobbyChatButton(
  57. participant: IKnockingParticipant
  58. ) {
  59. return function(state: IReduxState) {
  60. const { enableChat = true } = getLobbyConfig(state);
  61. const { lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];
  62. const conference = getCurrentConference(state);
  63. const lobbyLocalId = conference?.myLobbyUserId();
  64. if (!enableChat) {
  65. return false;
  66. }
  67. if (!isLobbyChatActive
  68. && (!participant.chattingWithModerator
  69. || participant.chattingWithModerator === lobbyLocalId)
  70. ) {
  71. return true;
  72. }
  73. if (isLobbyChatActive && lobbyMessageRecipient
  74. && participant.id !== lobbyMessageRecipient.id
  75. && (!participant.chattingWithModerator
  76. || participant.chattingWithModerator === lobbyLocalId)) {
  77. return true;
  78. }
  79. return false;
  80. };
  81. }
  82. /**
  83. * Returns true if enabling lobby is allowed and false otherwise.
  84. *
  85. * @param {IReduxState} state - State object.
  86. * @returns {boolean}
  87. */
  88. export function isEnablingLobbyAllowed(state: IReduxState) {
  89. return getVisitorsCount(state) <= 0;
  90. }