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

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