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.4KB

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