Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

reducer.js 14KB

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