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.

reducer.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
  2. import { JitsiConferenceErrors } from '../lib-jitsi-meet';
  3. import { assign, ReducerRegistry, set } from '../redux';
  4. import {
  5. CONFERENCE_FAILED,
  6. CONFERENCE_JOINED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_JOIN,
  9. CONFERENCE_WILL_LEAVE,
  10. LOCK_STATE_CHANGED,
  11. P2P_STATUS_CHANGED,
  12. SET_AUDIO_ONLY,
  13. SET_PASSWORD,
  14. SET_RECEIVE_VIDEO_QUALITY,
  15. SET_ROOM
  16. } from './actionTypes';
  17. import {
  18. VIDEO_QUALITY_LEVELS
  19. } from './constants';
  20. import { isRoomValid } from './functions';
  21. /**
  22. * Listen for actions that contain the conference object, so that it can be
  23. * stored for use by other action creators.
  24. */
  25. ReducerRegistry.register('features/base/conference', (state = {}, action) => {
  26. switch (action.type) {
  27. case CONFERENCE_FAILED:
  28. return _conferenceFailed(state, action);
  29. case CONFERENCE_JOINED:
  30. return _conferenceJoined(state, action);
  31. case CONFERENCE_LEFT:
  32. return _conferenceLeft(state, action);
  33. case CONFERENCE_WILL_JOIN:
  34. return _conferenceWillJoin(state, action);
  35. case CONFERENCE_WILL_LEAVE:
  36. return _conferenceWillLeave(state, action);
  37. case LOCK_STATE_CHANGED:
  38. return _lockStateChanged(state, action);
  39. case P2P_STATUS_CHANGED:
  40. return _p2pStatusChanged(state, action);
  41. case SET_AUDIO_ONLY:
  42. return _setAudioOnly(state, action);
  43. case SET_PASSWORD:
  44. return _setPassword(state, action);
  45. case SET_RECEIVE_VIDEO_QUALITY:
  46. return _setReceiveVideoQuality(state, action);
  47. case SET_ROOM:
  48. return _setRoom(state, action);
  49. }
  50. return state;
  51. });
  52. /**
  53. * Reduces a specific Redux action CONFERENCE_FAILED of the feature
  54. * base/conference.
  55. *
  56. * @param {Object} state - The Redux state of the feature base/conference.
  57. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  58. * @private
  59. * @returns {Object} The new state of the feature base/conference after the
  60. * reduction of the specified action.
  61. */
  62. function _conferenceFailed(state, { conference, error }) {
  63. if (state.conference && state.conference !== conference) {
  64. return state;
  65. }
  66. const passwordRequired
  67. = JitsiConferenceErrors.PASSWORD_REQUIRED === error
  68. ? conference
  69. : undefined;
  70. return assign(state, {
  71. conference: undefined,
  72. joining: undefined,
  73. leaving: undefined,
  74. /**
  75. * The indicator of how the conference/room is locked. If falsy, the
  76. * conference/room is unlocked; otherwise, it's either
  77. * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
  78. *
  79. * @type {string}
  80. */
  81. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  82. password: undefined,
  83. /**
  84. * The JitsiConference instance which requires a password to join.
  85. *
  86. * @type {JitsiConference}
  87. */
  88. passwordRequired
  89. });
  90. }
  91. /**
  92. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  93. * base/conference.
  94. *
  95. * @param {Object} state - The Redux state of the feature base/conference.
  96. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  97. * @private
  98. * @returns {Object} The new state of the feature base/conference after the
  99. * reduction of the specified action.
  100. */
  101. function _conferenceJoined(state, { conference }) {
  102. // FIXME The indicator which determines whether a JitsiConference is locked
  103. // i.e. password-protected is private to lib-jitsi-meet. However, the
  104. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  105. // with a password.
  106. const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
  107. return assign(state, {
  108. /**
  109. * The JitsiConference instance represented by the Redux state of the
  110. * feature base/conference.
  111. *
  112. * @type {JitsiConference}
  113. */
  114. conference,
  115. joining: undefined,
  116. leaving: undefined,
  117. /**
  118. * The indicator which determines whether the conference is locked.
  119. *
  120. * @type {boolean}
  121. */
  122. locked,
  123. passwordRequired: undefined,
  124. /**
  125. * The current resolution restraint on receiving remote video. By
  126. * default the conference will send the highest level possible.
  127. *
  128. * @type number
  129. */
  130. receiveVideoQuality: VIDEO_QUALITY_LEVELS.HIGH
  131. });
  132. }
  133. /**
  134. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  135. * base/conference.
  136. *
  137. * @param {Object} state - The Redux state of the feature base/conference.
  138. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  139. * @private
  140. * @returns {Object} The new state of the feature base/conference after the
  141. * reduction of the specified action.
  142. */
  143. function _conferenceLeft(state, { conference }) {
  144. if (state.conference !== conference) {
  145. return state;
  146. }
  147. return assign(state, {
  148. conference: undefined,
  149. joining: undefined,
  150. leaving: undefined,
  151. locked: undefined,
  152. password: undefined,
  153. passwordRequired: undefined
  154. });
  155. }
  156. /**
  157. * Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
  158. * base/conference.
  159. *
  160. * @param {Object} state - The Redux state of the feature base/conference.
  161. * @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
  162. * @private
  163. * @returns {Object} The new state of the feature base/conference after the
  164. * reduction of the specified action.
  165. */
  166. function _conferenceWillJoin(state, { conference }) {
  167. return set(state, 'joining', conference);
  168. }
  169. /**
  170. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
  171. * base/conference.
  172. *
  173. * @param {Object} state - The Redux state of the feature base/conference.
  174. * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
  175. * @private
  176. * @returns {Object} The new state of the feature base/conference after the
  177. * reduction of the specified action.
  178. */
  179. function _conferenceWillLeave(state, { conference }) {
  180. if (state.conference !== conference) {
  181. return state;
  182. }
  183. return assign(state, {
  184. joining: undefined,
  185. /**
  186. * The JitsiConference instance which is currently in the process of
  187. * being left.
  188. *
  189. * @type {JitsiConference}
  190. */
  191. leaving: conference,
  192. passwordRequired: undefined
  193. });
  194. }
  195. /**
  196. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  197. * base/conference.
  198. *
  199. * @param {Object} state - The Redux state of the feature base/conference.
  200. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  201. * @private
  202. * @returns {Object} The new state of the feature base/conference after the
  203. * reduction of the specified action.
  204. */
  205. function _lockStateChanged(state, { conference, locked }) {
  206. if (state.conference !== conference) {
  207. return state;
  208. }
  209. return assign(state, {
  210. locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
  211. password: locked ? state.password : undefined
  212. });
  213. }
  214. /**
  215. * Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
  216. * base/conference.
  217. *
  218. * @param {Object} state - The Redux state of the feature base/conference.
  219. * @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
  220. * @private
  221. * @returns {Object} The new state of the feature base/conference after the
  222. * reduction of the specified action.
  223. */
  224. function _p2pStatusChanged(state, action) {
  225. return set(state, 'p2p', action.p2p);
  226. }
  227. /**
  228. * Reduces a specific Redux action SET_AUDIO_ONLY of the feature
  229. * base/conference.
  230. *
  231. * @param {Object} state - The Redux state of the feature base/conference.
  232. * @param {Action} action - The Redux action SET_AUDIO_ONLY to reduce.
  233. * @private
  234. * @returns {Object} The new state of the feature base/conference after the
  235. * reduction of the specified action.
  236. */
  237. function _setAudioOnly(state, action) {
  238. return set(state, 'audioOnly', action.audioOnly);
  239. }
  240. /**
  241. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  242. *
  243. * @param {Object} state - The Redux state of the feature base/conference.
  244. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  245. * @private
  246. * @returns {Object} The new state of the feature base/conference after the
  247. * reduction of the specified action.
  248. */
  249. function _setPassword(state, { conference, method, password }) {
  250. switch (method) {
  251. case conference.join:
  252. if (state.passwordRequired === conference) {
  253. return assign(state, {
  254. locked: LOCKED_REMOTELY,
  255. /**
  256. * The password with which the conference is to be joined.
  257. *
  258. * @type {string}
  259. */
  260. password,
  261. passwordRequired: undefined
  262. });
  263. }
  264. break;
  265. case conference.lock:
  266. return assign(state, {
  267. locked: password ? LOCKED_LOCALLY : undefined,
  268. password
  269. });
  270. }
  271. return state;
  272. }
  273. /**
  274. * Reduces a specific Redux action SET_RECEIVE_VIDEO_QUALITY of the feature
  275. * base/conference.
  276. *
  277. * @param {Object} state - The Redux state of the feature base/conference.
  278. * @param {Action} action - The Redux action SET_RECEIVE_VIDEO_QUALITY to
  279. * reduce.
  280. * @private
  281. * @returns {Object} The new state of the feature base/conference after the
  282. * reduction of the specified action.
  283. */
  284. function _setReceiveVideoQuality(state, action) {
  285. return set(state, 'receiveVideoQuality', action.receiveVideoQuality);
  286. }
  287. /**
  288. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  289. *
  290. * @param {Object} state - The Redux state of the feature base/conference.
  291. * @param {Action} action - The Redux action SET_ROOM to reduce.
  292. * @private
  293. * @returns {Object} The new state of the feature base/conference after the
  294. * reduction of the specified action.
  295. */
  296. function _setRoom(state, action) {
  297. let room = action.room;
  298. if (!isRoomValid(room)) {
  299. // Technically, there are multiple values which don't represent valid
  300. // room names. Practically, each of them is as bad as the rest of them
  301. // because we can't use any of them to join a conference.
  302. room = undefined;
  303. }
  304. /**
  305. * The name of the room of the conference (to be) joined.
  306. *
  307. * @type {string}
  308. */
  309. return set(state, 'room', room);
  310. }