Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

reducer.js 11KB

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