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

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