Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.ts 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {
  2. CONFERENCE_FAILED,
  3. CONFERENCE_JOINED,
  4. CONFERENCE_LEFT,
  5. SET_PASSWORD
  6. } from '../base/conference/actionTypes';
  7. import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
  8. import ReducerRegistry from '../base/redux/ReducerRegistry';
  9. import {
  10. KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
  11. KNOCKING_PARTICIPANT_LEFT,
  12. REMOVE_LOBBY_CHAT_WITH_MODERATOR,
  13. SET_KNOCKING_STATE,
  14. SET_LOBBY_MODE_ENABLED,
  15. SET_LOBBY_PARTICIPANT_CHAT_STATE,
  16. SET_LOBBY_VISIBILITY,
  17. SET_PASSWORD_JOIN_FAILED
  18. } from './actionTypes';
  19. import { IKnockingParticipant } from './types';
  20. const DEFAULT_STATE = {
  21. isDisplayNameRequiredError: false,
  22. knocking: false,
  23. knockingParticipants: [],
  24. lobbyEnabled: false,
  25. lobbyVisible: false,
  26. passwordJoinFailed: false
  27. };
  28. export interface ILobbyState {
  29. /**
  30. * A conference error when we tried to join into a room with no display name
  31. * when lobby is enabled in the room.
  32. */
  33. isDisplayNameRequiredError: boolean;
  34. knocking: boolean;
  35. knockingParticipants: IKnockingParticipant[];
  36. lobbyEnabled: boolean;
  37. lobbyVisible: boolean;
  38. passwordJoinFailed: boolean;
  39. }
  40. /**
  41. * Reduces redux actions which affect the display of notifications.
  42. *
  43. * @param {Object} state - The current redux state.
  44. * @param {Object} action - The redux action to reduce.
  45. * @returns {Object} The next redux state which is the result of reducing the
  46. * specified {@code action}.
  47. */
  48. ReducerRegistry.register<ILobbyState>('features/lobby', (state = DEFAULT_STATE, action): ILobbyState => {
  49. switch (action.type) {
  50. case CONFERENCE_FAILED: {
  51. if (action.error.name === JitsiConferenceErrors.DISPLAY_NAME_REQUIRED) {
  52. return {
  53. ...state,
  54. isDisplayNameRequiredError: true
  55. };
  56. }
  57. return state;
  58. }
  59. case CONFERENCE_JOINED:
  60. case CONFERENCE_LEFT:
  61. return {
  62. ...state,
  63. knocking: false,
  64. passwordJoinFailed: false
  65. };
  66. case KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED:
  67. return _knockingParticipantArrivedOrUpdated(action.participant, state);
  68. case KNOCKING_PARTICIPANT_LEFT:
  69. return {
  70. ...state,
  71. knockingParticipants: state.knockingParticipants.filter(p => p.id !== action.id)
  72. };
  73. case SET_KNOCKING_STATE:
  74. return {
  75. ...state,
  76. knocking: action.knocking,
  77. passwordJoinFailed: false
  78. };
  79. case SET_LOBBY_MODE_ENABLED:
  80. return {
  81. ...state,
  82. lobbyEnabled: action.enabled
  83. };
  84. case SET_LOBBY_VISIBILITY:
  85. return {
  86. ...state,
  87. lobbyVisible: action.visible
  88. };
  89. case SET_PASSWORD:
  90. return {
  91. ...state,
  92. passwordJoinFailed: false
  93. };
  94. case SET_PASSWORD_JOIN_FAILED:
  95. return {
  96. ...state,
  97. passwordJoinFailed: action.failed
  98. };
  99. case SET_LOBBY_PARTICIPANT_CHAT_STATE:
  100. return {
  101. ...state,
  102. knockingParticipants: state.knockingParticipants.map(participant => {
  103. if (participant.id === action.participant.id) {
  104. return {
  105. ...participant,
  106. chattingWithModerator: action.moderator.id
  107. };
  108. }
  109. return participant;
  110. })
  111. };
  112. case REMOVE_LOBBY_CHAT_WITH_MODERATOR:
  113. return {
  114. ...state,
  115. knockingParticipants: state.knockingParticipants.map(participant => {
  116. if (participant.chattingWithModerator === action.moderatorId) {
  117. return {
  118. ...participant,
  119. chattingWithModerator: undefined
  120. };
  121. }
  122. return participant;
  123. })
  124. };
  125. }
  126. return state;
  127. });
  128. /**
  129. * Stores or updates a knocking participant.
  130. *
  131. * @param {Object} participant - The arrived or updated knocking participant.
  132. * @param {Object} state - The current Redux state of the feature.
  133. * @returns {Object}
  134. */
  135. function _knockingParticipantArrivedOrUpdated(participant: IKnockingParticipant, state: ILobbyState) {
  136. let existingParticipant = state.knockingParticipants.find(p => p.id === participant.id);
  137. existingParticipant = {
  138. ...existingParticipant,
  139. ...participant
  140. };
  141. return {
  142. ...state,
  143. knockingParticipants: [
  144. ...state.knockingParticipants.filter(p => p.id !== participant.id),
  145. existingParticipant
  146. ]
  147. };
  148. }