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.

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