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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Returns local participant from Redux state.
  3. *
  4. * @param {(Function|Participant[])} participantsOrGetState - Either the
  5. * features/base/participants Redux state or Redux's getState function to be
  6. * used to retrieve the features/base/participants state.
  7. * @returns {(Participant|undefined)}
  8. */
  9. export function getLocalParticipant(participantsOrGetState) {
  10. const participants = _getParticipants(participantsOrGetState);
  11. return participants.find(p => p.local);
  12. }
  13. /**
  14. * Returns participant by ID from Redux state.
  15. *
  16. * @param {(Function|Participant[])} participantsOrGetState - Either the
  17. * features/base/participants Redux state or Redux's getState function to be
  18. * used to retrieve the features/base/participants state.
  19. * @param {string} id - The ID of the participant to retrieve.
  20. * @private
  21. * @returns {(Participant|undefined)}
  22. */
  23. export function getParticipantById(participantsOrGetState, id) {
  24. const participants = _getParticipants(participantsOrGetState);
  25. return participants.find(p => p.id === id);
  26. }
  27. /**
  28. * Returns array of participants from Redux state.
  29. *
  30. * @param {(Function|Participant[])} participantsOrGetState - Either the
  31. * features/base/participants Redux state or Redux's getState function to be
  32. * used to retrieve the features/base/participants state.
  33. * @private
  34. * @returns {Participant[]}
  35. */
  36. function _getParticipants(participantsOrGetState) {
  37. const participants
  38. = typeof participantsOrGetState === 'function'
  39. ? participantsOrGetState()['features/base/participants']
  40. : participantsOrGetState;
  41. return participants || [];
  42. }