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

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