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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
  2. import { JitsiConferenceErrors } from '../lib-jitsi-meet';
  3. import { assign, ReducerRegistry, set } from '../redux';
  4. import {
  5. CONFERENCE_FAILED,
  6. CONFERENCE_JOINED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_LEAVE,
  9. LOCK_STATE_CHANGED,
  10. SET_AUDIO_ONLY,
  11. _SET_AUDIO_ONLY_VIDEO_MUTED,
  12. SET_PASSWORD,
  13. SET_ROOM
  14. } from './actionTypes';
  15. import { isRoomValid } from './functions';
  16. /**
  17. * Listen for actions that contain the conference object, so that it can be
  18. * stored for use by other action creators.
  19. */
  20. ReducerRegistry.register('features/base/conference', (state = {}, action) => {
  21. switch (action.type) {
  22. case CONFERENCE_FAILED:
  23. return _conferenceFailed(state, action);
  24. case CONFERENCE_JOINED:
  25. return _conferenceJoined(state, action);
  26. case CONFERENCE_LEFT:
  27. return _conferenceLeft(state, action);
  28. case CONFERENCE_WILL_LEAVE:
  29. return _conferenceWillLeave(state, action);
  30. case LOCK_STATE_CHANGED:
  31. return _lockStateChanged(state, action);
  32. case SET_AUDIO_ONLY:
  33. return _setAudioOnly(state, action);
  34. case _SET_AUDIO_ONLY_VIDEO_MUTED:
  35. return _setAudioOnlyVideoMuted(state, action);
  36. case SET_PASSWORD:
  37. return _setPassword(state, action);
  38. case SET_ROOM:
  39. return _setRoom(state, action);
  40. }
  41. return state;
  42. });
  43. /**
  44. * Reduces a specific Redux action CONFERENCE_FAILED of the feature
  45. * base/conference.
  46. *
  47. * @param {Object} state - The Redux state of the feature base/conference.
  48. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  49. * @private
  50. * @returns {Object} The new state of the feature base/conference after the
  51. * reduction of the specified action.
  52. */
  53. function _conferenceFailed(state, action) {
  54. const conference = action.conference;
  55. if (state.conference && state.conference !== conference) {
  56. return state;
  57. }
  58. const passwordRequired
  59. = JitsiConferenceErrors.PASSWORD_REQUIRED === action.error
  60. ? conference
  61. : undefined;
  62. return (
  63. assign(state, {
  64. audioOnly: undefined,
  65. audioOnlyVideoMuted: undefined,
  66. conference: undefined,
  67. leaving: undefined,
  68. /**
  69. * The indicator of how the conference/room is locked. If falsy, the
  70. * conference/room is unlocked; otherwise, it's either
  71. * {@code LOCKED_LOCALLY| or {@code LOCKED_REMOTELY}.
  72. *
  73. * @type {string}
  74. */
  75. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  76. password: undefined,
  77. /**
  78. * The JitsiConference instance which requires a password to join.
  79. *
  80. * @type {JitsiConference}
  81. */
  82. passwordRequired
  83. }));
  84. }
  85. /**
  86. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  87. * base/conference.
  88. *
  89. * @param {Object} state - The Redux state of the feature base/conference.
  90. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  91. * @private
  92. * @returns {Object} The new state of the feature base/conference after the
  93. * reduction of the specified action.
  94. */
  95. function _conferenceJoined(state, action) {
  96. const conference = action.conference;
  97. // FIXME The indicator which determines whether a JitsiConference is locked
  98. // i.e. password-protected is private to lib-jitsi-meet. However, the
  99. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  100. // with a password.
  101. const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
  102. return (
  103. assign(state, {
  104. /**
  105. * The JitsiConference instance represented by the Redux state of
  106. * the feature base/conference.
  107. *
  108. * @type {JitsiConference}
  109. */
  110. conference,
  111. leaving: undefined,
  112. /**
  113. * The indicator which determines whether the conference is locked.
  114. *
  115. * @type {boolean}
  116. */
  117. locked,
  118. passwordRequired: undefined
  119. }));
  120. }
  121. /**
  122. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  123. * base/conference.
  124. *
  125. * @param {Object} state - The Redux state of the feature base/conference.
  126. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  127. * @private
  128. * @returns {Object} The new state of the feature base/conference after the
  129. * reduction of the specified action.
  130. */
  131. function _conferenceLeft(state, action) {
  132. const conference = action.conference;
  133. if (state.conference !== conference) {
  134. return state;
  135. }
  136. return (
  137. assign(state, {
  138. audioOnly: undefined,
  139. audioOnlyVideoMuted: undefined,
  140. conference: undefined,
  141. leaving: undefined,
  142. locked: undefined,
  143. password: undefined,
  144. passwordRequired: undefined
  145. }));
  146. }
  147. /**
  148. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE 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_WILL_LEAVE 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 _conferenceWillLeave(state, action) {
  158. const conference = action.conference;
  159. if (state.conference !== conference) {
  160. return state;
  161. }
  162. return (
  163. assign(state, {
  164. /**
  165. * The JitsiConference instance which is currently in the process of
  166. * being left.
  167. *
  168. * @type {JitsiConference}
  169. */
  170. leaving: conference,
  171. passwordRequired: undefined
  172. }));
  173. }
  174. /**
  175. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  176. * base/conference.
  177. *
  178. * @param {Object} state - The Redux state of the feature base/conference.
  179. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  180. * @private
  181. * @returns {Object} The new state of the feature base/conference after the
  182. * reduction of the specified action.
  183. */
  184. function _lockStateChanged(state, action) {
  185. if (state.conference !== action.conference) {
  186. return state;
  187. }
  188. let locked;
  189. if (action.locked) {
  190. locked = state.locked || LOCKED_REMOTELY;
  191. }
  192. return assign(state, {
  193. locked,
  194. password: action.locked ? state.password : null
  195. });
  196. }
  197. /**
  198. * Reduces a specific Redux action SET_AUDIO_ONLY of the feature
  199. * base/conference.
  200. *
  201. * @param {Object} state - The Redux state of the feature base/conference.
  202. * @param {Action} action - The Redux action SET_AUDIO_ONLY to reduce.
  203. * @private
  204. * @returns {Object} The new state of the feature base/conference after the
  205. * reduction of the specified action.
  206. */
  207. function _setAudioOnly(state, action) {
  208. return set(state, 'audioOnly', action.audioOnly);
  209. }
  210. /**
  211. * Reduces a specific Redux action _SET_AUDIO_ONLY_VIDEO_MUTED of the feature
  212. * base/conference.
  213. *
  214. * @param {Object} state - The Redux state of the feature base/conference.
  215. * @param {Action} action - The Redux action SET_AUDIO_ONLY_VIDEO_MUTED to
  216. * reduce.
  217. * @private
  218. * @returns {Object} The new state of the feature base/conference after the
  219. * reduction of the specified action.
  220. */
  221. function _setAudioOnlyVideoMuted(state, action) {
  222. return set(state, 'audioOnlyVideoMuted', action.muted);
  223. }
  224. /**
  225. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  226. *
  227. * @param {Object} state - The Redux state of the feature base/conference.
  228. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  229. * @private
  230. * @returns {Object} The new state of the feature base/conference after the
  231. * reduction of the specified action.
  232. */
  233. function _setPassword(state, action) {
  234. const conference = action.conference;
  235. switch (action.method) {
  236. case conference.join:
  237. if (state.passwordRequired === conference) {
  238. return (
  239. assign(state, {
  240. locked: LOCKED_REMOTELY,
  241. /**
  242. * The password with which the conference is to be joined.
  243. *
  244. * @type {string}
  245. */
  246. password: action.password,
  247. passwordRequired: undefined
  248. }));
  249. }
  250. break;
  251. case conference.lock:
  252. return assign(state, {
  253. locked: action.password ? LOCKED_LOCALLY : undefined,
  254. password: action.password
  255. });
  256. }
  257. return state;
  258. }
  259. /**
  260. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  261. *
  262. * @param {Object} state - The Redux state of the feature base/conference.
  263. * @param {Action} action - The Redux action SET_ROOM to reduce.
  264. * @private
  265. * @returns {Object} The new state of the feature base/conference after the
  266. * reduction of the specified action.
  267. */
  268. function _setRoom(state, action) {
  269. let room = action.room;
  270. if (!isRoomValid(room)) {
  271. // Technically, there are multiple values which don't represent valid
  272. // room names. Practically, each of them is as bad as the rest of them
  273. // because we can't use any of them to join a conference.
  274. room = undefined;
  275. }
  276. /**
  277. * The name of the room of the conference (to be) joined.
  278. *
  279. * @type {string}
  280. */
  281. return set(state, 'room', room);
  282. }