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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // @flow
  2. import _ from 'lodash';
  3. import { getCurrentConference } from '../base/conference';
  4. import { getParticipantCount, isLocalParticipantModerator } from '../base/participants';
  5. import { toState } from '../base/redux';
  6. import { FEATURE_KEY } from './constants';
  7. /**
  8. * Returns the rooms object for breakout rooms.
  9. *
  10. * @param {Function|Object} stateful - The redux store, the redux
  11. * {@code getState} function, or the redux state itself.
  12. * @returns {Object} Object of rooms.
  13. */
  14. export const getBreakoutRooms = (stateful: Function | Object) => toState(stateful)[FEATURE_KEY].rooms;
  15. /**
  16. * Returns the main room.
  17. *
  18. * @param {Function|Object} stateful - The redux store, the redux
  19. * {@code getState} function, or the redux state itself.
  20. * @returns {Object|undefined} The main room object, or undefined.
  21. */
  22. export const getMainRoom = (stateful: Function | Object) => {
  23. const rooms = getBreakoutRooms(stateful);
  24. return _.find(rooms, (room: Object) => room.isMainRoom);
  25. };
  26. /**
  27. * Returns the room by Jid.
  28. *
  29. * @param {Function|Object} stateful - The redux store, the redux
  30. * {@code getState} function, or the redux state itself.
  31. * @param {string} roomJid - The jid of the room.
  32. * @returns {Object|undefined} The main room object, or undefined.
  33. */
  34. export const getRoomByJid = (stateful: Function | Object, roomJid: string): Object => {
  35. const rooms = getBreakoutRooms(stateful);
  36. return _.find(rooms, (room: Object) => room.jid === roomJid);
  37. };
  38. /**
  39. * Returns the id of the current room.
  40. *
  41. * @param {Function|Object} stateful - The redux store, the redux
  42. * {@code getState} function, or the redux state itself.
  43. * @returns {string} Room id or undefined.
  44. */
  45. export const getCurrentRoomId = (stateful: Function | Object) => {
  46. const conference = getCurrentConference(stateful);
  47. // $FlowExpectedError
  48. return conference?.getName();
  49. };
  50. /**
  51. * Determines whether the local participant is in a breakout room.
  52. *
  53. * @param {Function|Object} stateful - The redux store, the redux
  54. * {@code getState} function, or the redux state itself.
  55. * @returns {boolean}
  56. */
  57. export const isInBreakoutRoom = (stateful: Function | Object) => {
  58. const conference = getCurrentConference(stateful);
  59. // $FlowExpectedError
  60. return conference?.getBreakoutRooms()
  61. ?.isBreakoutRoom();
  62. };
  63. /**
  64. * Returns the breakout rooms config.
  65. *
  66. * @param {Function|Object} stateful - The redux store, the redux
  67. * {@code getState} function, or the redux state itself.
  68. * @returns {Object}
  69. */
  70. export const getBreakoutRoomsConfig = (stateful: Function | Object) => {
  71. const state = toState(stateful);
  72. const { breakoutRooms = {} } = state['features/base/config'];
  73. return breakoutRooms;
  74. };
  75. /**
  76. * Returns whether the add breakout room button is visible.
  77. *
  78. * @param {Function | Object} stateful - Global state.
  79. * @returns {boolean}
  80. */
  81. export const isAddBreakoutRoomButtonVisible = (stateful: Function | Object) => {
  82. const state = toState(stateful);
  83. const isLocalModerator = isLocalParticipantModerator(state);
  84. const { conference } = state['features/base/conference'];
  85. const isBreakoutRoomsSupported = conference?.getBreakoutRooms()?.isSupported();
  86. const { hideAddRoomButton } = getBreakoutRoomsConfig(state);
  87. return isLocalModerator && isBreakoutRoomsSupported && !hideAddRoomButton;
  88. };
  89. /**
  90. * Returns whether the auto assign participants to breakout rooms button is visible.
  91. *
  92. * @param {Function | Object} stateful - Global state.
  93. * @returns {boolean}
  94. */
  95. export const isAutoAssignParticipantsVisible = (stateful: Function | Object) => {
  96. const state = toState(stateful);
  97. const rooms = getBreakoutRooms(state);
  98. const inBreakoutRoom = isInBreakoutRoom(state);
  99. const isLocalModerator = isLocalParticipantModerator(state);
  100. const participantsCount = getParticipantCount(state);
  101. const { hideAutoAssignButton } = getBreakoutRoomsConfig(state);
  102. return !inBreakoutRoom
  103. && isLocalModerator
  104. && participantsCount > 2
  105. && Object.keys(rooms).length > 1
  106. && !hideAutoAssignButton;
  107. };