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.

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