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.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // @flow
  2. import { getCurrentConference } from '../base/conference';
  3. import { toState } from '../base/redux';
  4. const JID_PATTERN = '[^@]+@[^/]+/(.+)';
  5. /**
  6. * Returns a knocking participant by ID or JID.
  7. *
  8. * @param {Function | Object} stateful - The Redux state or a function that resolves to the Redux state.
  9. * @param {string} id - The ID or JID of the participant.
  10. * @returns {Object}
  11. */
  12. export function getKnockingParticipantById(stateful: Function | Object, id: string): Object {
  13. const { knockingParticipants } = toState(stateful)['features/lobby'];
  14. const idToFind = getIdFromJid(id) || id;
  15. return knockingParticipants.find(p => p.id === idToFind);
  16. }
  17. /**
  18. * Approves (lets in) or rejects a knocking participant.
  19. *
  20. * @param {Function} getState - Function to get the Redux state.
  21. * @param {string} id - The id of the knocking participant.
  22. * @param {boolean} approved - True if the participant is approved, false otherwise.
  23. * @returns {Function}
  24. */
  25. export function setKnockingParticipantApproval(getState: Function, id: string, approved: boolean) {
  26. const conference = getCurrentConference(getState());
  27. if (conference) {
  28. if (approved) {
  29. conference.lobbyApproveAccess(id);
  30. } else {
  31. conference.lobbyDenyAccess(id);
  32. }
  33. }
  34. }
  35. /**
  36. * Parses an ID from a JID, if a JID is provided, undefined otherwise.
  37. *
  38. * @param {string} jid - The JID to get the ID from.
  39. * @returns {?string}
  40. */
  41. function getIdFromJid(jid: string): ?string {
  42. const match = new RegExp(JID_PATTERN, 'g').exec(jid) || [];
  43. return match[1];
  44. }