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.

fbp_reducer.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // @flow
  2. import { ReducerRegistry, set } from '../redux';
  3. import {
  4. DOMINANT_SPEAKER_CHANGED,
  5. PARTICIPANT_ID_CHANGED,
  6. PARTICIPANT_JOINED,
  7. PARTICIPANT_LEFT,
  8. PARTICIPANT_UPDATED,
  9. PIN_PARTICIPANT,
  10. SET_LOADABLE_AVATAR_URL
  11. } from './actionTypes';
  12. import { LOCAL_PARTICIPANT_DEFAULT_ID, PARTICIPANT_ROLE } from './constants';
  13. /**
  14. * Participant object.
  15. * @typedef {Object} Participant
  16. * @property {string} id - Participant ID.
  17. * @property {string} name - Participant name.
  18. * @property {string} avatar - Path to participant avatar if any.
  19. * @property {string} role - Participant role.
  20. * @property {boolean} local - If true, participant is local.
  21. * @property {boolean} pinned - If true, participant is currently a
  22. * "PINNED_ENDPOINT".
  23. * @property {boolean} dominantSpeaker - If this participant is the dominant
  24. * speaker in the (associated) conference, {@code true}; otherwise,
  25. * {@code false}.
  26. * @property {string} email - Participant email.
  27. */
  28. declare var APP: Object;
  29. /**
  30. * The participant properties which cannot be updated through
  31. * {@link PARTICIPANT_UPDATED}. They either identify the participant or can only
  32. * be modified through property-dedicated actions.
  33. *
  34. * @type {string[]}
  35. */
  36. const PARTICIPANT_PROPS_TO_OMIT_WHEN_UPDATE = [
  37. // The following properties identify the participant:
  38. 'conference',
  39. 'id',
  40. 'local',
  41. // The following properties can only be modified through property-dedicated
  42. // actions:
  43. 'dominantSpeaker',
  44. 'pinned'
  45. ];
  46. /**
  47. * Listen for actions which add, remove, or update the set of participants in
  48. * the conference.
  49. *
  50. * @param {Participant[]} state - List of participants to be modified.
  51. * @param {Object} action - Action object.
  52. * @param {string} action.type - Type of action.
  53. * @param {Participant} action.participant - Information about participant to be
  54. * added/removed/modified.
  55. * @returns {Participant[]}
  56. */
  57. ReducerRegistry.register('features/base/participants', (state = [], action) => {
  58. var ret
  59. switch (action.type) {
  60. case SET_LOADABLE_AVATAR_URL:
  61. case DOMINANT_SPEAKER_CHANGED:
  62. case PARTICIPANT_ID_CHANGED:
  63. case PARTICIPANT_UPDATED:
  64. case PIN_PARTICIPANT:
  65. // var ret2 = _participant(p, action)
  66. // ret =state.map(p => ret2);
  67. ret =state.map(p => _participant(p, action));
  68. ret = new Proxy(ret,gen_proxy())
  69. // clog("ATYPE",{ret,ret2,p ,action})
  70. clog("ATYPE",action.type,{ret})
  71. return ret
  72. // return state.map(p => _participant(p, action));
  73. case PARTICIPANT_JOINED:
  74. // dev inspect
  75. const participant_new = _participantJoined(action)
  76. clog("PARTICIPANT_JOINED RFN dev inspect",{state,action,participant_new})
  77. ret = [ ...state, participant_new ]
  78. clog("PARTICIPANT_JOINED RFN dev inspect2",ret)
  79. ret = new Proxy(ret,gen_proxy())
  80. clog("PARTICIPANT_JOINED RFN dev inspect3",ret)
  81. // const ret = new Proxy([ ...state, participant_new ],rprox)
  82. return ret;
  83. // return [ ...state, _participantJoined(action) ];
  84. case PARTICIPANT_LEFT: {
  85. // XXX A remote participant is uniquely identified by their id in a
  86. // specific JitsiConference instance. The local participant is uniquely
  87. // identified by the very fact that there is only one local participant
  88. // (and the fact that the local participant "joins" at the beginning of
  89. // the app and "leaves" at the end of the app).
  90. const { conference, id } = action.participant;
  91. return state.filter(p =>
  92. !(
  93. p.id === id
  94. // XXX Do not allow collisions in the IDs of the local
  95. // participant and a remote participant cause the removal of
  96. // the local participant when the remote participant's
  97. // removal is requested.
  98. && p.conference === conference
  99. && (conference || p.local)));
  100. }
  101. }
  102. return state;
  103. });
  104. /**
  105. * Reducer function for a single participant.
  106. *
  107. * @param {Participant|undefined} state - Participant to be modified.
  108. * @param {Object} action - Action object.
  109. * @param {string} action.type - Type of action.
  110. * @param {Participant} action.participant - Information about participant to be
  111. * added/modified.
  112. * @param {JitsiConference} action.conference - Conference instance.
  113. * @private
  114. * @returns {Participant}
  115. */
  116. function _participant(state: Object = {}, action) {
  117. switch (action.type) {
  118. case DOMINANT_SPEAKER_CHANGED:
  119. // Only one dominant speaker is allowed.
  120. return (
  121. set(state, 'dominantSpeaker', state.id === action.participant.id));
  122. case PARTICIPANT_ID_CHANGED: {
  123. // A participant is identified by an id-conference pair. Only the local
  124. // participant is with an undefined conference.
  125. const { conference } = action;
  126. if (state.id === action.oldValue
  127. && state.conference === conference
  128. && (conference || state.local)) {
  129. return {
  130. ...state,
  131. id: action.newValue
  132. };
  133. }
  134. break;
  135. }
  136. case SET_LOADABLE_AVATAR_URL:
  137. case PARTICIPANT_UPDATED: {
  138. const { participant } = action; // eslint-disable-line no-shadow
  139. let { id } = participant;
  140. const { local } = participant;
  141. if (!id && local) {
  142. id = LOCAL_PARTICIPANT_DEFAULT_ID;
  143. }
  144. if (state.id === id) {
  145. const newState = { ...state };
  146. for (const key in participant) {
  147. if (participant.hasOwnProperty(key)
  148. && PARTICIPANT_PROPS_TO_OMIT_WHEN_UPDATE.indexOf(key)
  149. === -1) {
  150. newState[key] = participant[key];
  151. }
  152. }
  153. return newState;
  154. }
  155. break;
  156. }
  157. case PIN_PARTICIPANT:
  158. // Currently, only one pinned participant is allowed.
  159. return set(state, 'pinned', state.id === action.participant.id);
  160. }
  161. return state;
  162. }
  163. /**
  164. * Reduces a specific redux action of type {@link PARTICIPANT_JOINED} in the
  165. * feature base/participants.
  166. *
  167. * @param {Action} action - The redux action of type {@code PARTICIPANT_JOINED}
  168. * to reduce.
  169. * @private
  170. * @returns {Object} The new participant derived from the payload of the
  171. * specified {@code action} to be added into the redux state of the feature
  172. * base/participants after the reduction of the specified
  173. * {@code action}.
  174. */
  175. function _participantJoined({ participant }) {
  176. const {
  177. avatarID,
  178. avatarURL,
  179. botType,
  180. connectionStatus,
  181. dominantSpeaker,
  182. email,
  183. isFakeParticipant,
  184. isJigasi,
  185. loadableAvatarUrl,
  186. local,
  187. name,
  188. pinned,
  189. presence,
  190. role
  191. } = participant;
  192. let { conference, id } = participant;
  193. if (local) {
  194. // conference
  195. //
  196. // XXX The local participant is not identified in association with a
  197. // JitsiConference because it is identified by the very fact that it is
  198. // the local participant.
  199. conference = undefined;
  200. // id
  201. id || (id = LOCAL_PARTICIPANT_DEFAULT_ID);
  202. }
  203. return {
  204. avatarID,
  205. avatarURL,
  206. botType,
  207. conference,
  208. connectionStatus,
  209. dominantSpeaker: dominantSpeaker || false,
  210. email,
  211. id,
  212. isFakeParticipant,
  213. isJigasi,
  214. loadableAvatarUrl,
  215. local: local || false,
  216. name,
  217. pinned: pinned || false,
  218. presence,
  219. role: role || PARTICIPANT_ROLE.NONE
  220. };
  221. }