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.js 15KB

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