Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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_JOIN,
  9. CONFERENCE_WILL_LEAVE,
  10. LOCK_STATE_CHANGED,
  11. SET_AUDIO_ONLY,
  12. _SET_AUDIO_ONLY_VIDEO_MUTED,
  13. SET_LARGE_VIDEO_HD_STATUS,
  14. SET_PASSWORD,
  15. SET_ROOM
  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_JOIN:
  31. return _conferenceWillJoin(state, action);
  32. case CONFERENCE_WILL_LEAVE:
  33. return _conferenceWillLeave(state, action);
  34. case LOCK_STATE_CHANGED:
  35. return _lockStateChanged(state, action);
  36. case SET_AUDIO_ONLY:
  37. return _setAudioOnly(state, action);
  38. case _SET_AUDIO_ONLY_VIDEO_MUTED:
  39. return _setAudioOnlyVideoMuted(state, action);
  40. case SET_LARGE_VIDEO_HD_STATUS:
  41. return _setLargeVideoHDStatus(state, action);
  42. case SET_PASSWORD:
  43. return _setPassword(state, action);
  44. case SET_ROOM:
  45. return _setRoom(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, { conference, error }) {
  60. if (state.conference && state.conference !== conference) {
  61. return state;
  62. }
  63. const passwordRequired
  64. = JitsiConferenceErrors.PASSWORD_REQUIRED === error
  65. ? conference
  66. : undefined;
  67. return assign(state, {
  68. audioOnly: undefined,
  69. audioOnlyVideoMuted: undefined,
  70. conference: undefined,
  71. joining: undefined,
  72. leaving: undefined,
  73. /**
  74. * The indicator of how the conference/room is locked. If falsy, the
  75. * conference/room is unlocked; otherwise, it's either
  76. * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
  77. *
  78. * @type {string}
  79. */
  80. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  81. password: undefined,
  82. /**
  83. * The JitsiConference instance which requires a password to join.
  84. *
  85. * @type {JitsiConference}
  86. */
  87. passwordRequired
  88. });
  89. }
  90. /**
  91. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  92. * base/conference.
  93. *
  94. * @param {Object} state - The Redux state of the feature base/conference.
  95. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  96. * @private
  97. * @returns {Object} The new state of the feature base/conference after the
  98. * reduction of the specified action.
  99. */
  100. function _conferenceJoined(state, { conference }) {
  101. // FIXME The indicator which determines whether a JitsiConference is locked
  102. // i.e. password-protected is private to lib-jitsi-meet. However, the
  103. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  104. // with a password.
  105. const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
  106. return assign(state, {
  107. /**
  108. * The JitsiConference instance represented by the Redux state of the
  109. * feature base/conference.
  110. *
  111. * @type {JitsiConference}
  112. */
  113. conference,
  114. joining: undefined,
  115. leaving: undefined,
  116. /**
  117. * The indicator which determines whether the conference is locked.
  118. *
  119. * @type {boolean}
  120. */
  121. locked,
  122. passwordRequired: undefined
  123. });
  124. }
  125. /**
  126. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  127. * base/conference.
  128. *
  129. * @param {Object} state - The Redux state of the feature base/conference.
  130. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  131. * @private
  132. * @returns {Object} The new state of the feature base/conference after the
  133. * reduction of the specified action.
  134. */
  135. function _conferenceLeft(state, { conference }) {
  136. if (state.conference !== conference) {
  137. return state;
  138. }
  139. return assign(state, {
  140. audioOnly: undefined,
  141. audioOnlyVideoMuted: undefined,
  142. conference: undefined,
  143. joining: undefined,
  144. leaving: undefined,
  145. locked: undefined,
  146. password: undefined,
  147. passwordRequired: undefined
  148. });
  149. }
  150. /**
  151. * Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
  152. * base/conference.
  153. *
  154. * @param {Object} state - The Redux state of the feature base/conference.
  155. * @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
  156. * @private
  157. * @returns {Object} The new state of the feature base/conference after the
  158. * reduction of the specified action.
  159. */
  160. function _conferenceWillJoin(state, { conference }) {
  161. return set(state, 'joining', conference);
  162. }
  163. /**
  164. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
  165. * base/conference.
  166. *
  167. * @param {Object} state - The Redux state of the feature base/conference.
  168. * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
  169. * @private
  170. * @returns {Object} The new state of the feature base/conference after the
  171. * reduction of the specified action.
  172. */
  173. function _conferenceWillLeave(state, { conference }) {
  174. if (state.conference !== conference) {
  175. return state;
  176. }
  177. return assign(state, {
  178. joining: undefined,
  179. /**
  180. * The JitsiConference instance which is currently in the process of
  181. * being left.
  182. *
  183. * @type {JitsiConference}
  184. */
  185. leaving: conference,
  186. passwordRequired: undefined
  187. });
  188. }
  189. /**
  190. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  191. * base/conference.
  192. *
  193. * @param {Object} state - The Redux state of the feature base/conference.
  194. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  195. * @private
  196. * @returns {Object} The new state of the feature base/conference after the
  197. * reduction of the specified action.
  198. */
  199. function _lockStateChanged(state, { conference, locked }) {
  200. if (state.conference !== conference) {
  201. return state;
  202. }
  203. return assign(state, {
  204. locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
  205. password: locked ? state.password : undefined
  206. });
  207. }
  208. /**
  209. * Reduces a specific Redux action SET_AUDIO_ONLY 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 SET_AUDIO_ONLY 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 _setAudioOnly(state, action) {
  219. return set(state, 'audioOnly', action.audioOnly);
  220. }
  221. /**
  222. * Reduces a specific Redux action _SET_AUDIO_ONLY_VIDEO_MUTED of the feature
  223. * base/conference.
  224. *
  225. * @param {Object} state - The Redux state of the feature base/conference.
  226. * @param {Action} action - The Redux action SET_AUDIO_ONLY_VIDEO_MUTED to
  227. * reduce.
  228. * @private
  229. * @returns {Object} The new state of the feature base/conference after the
  230. * reduction of the specified action.
  231. */
  232. function _setAudioOnlyVideoMuted(state, action) {
  233. return set(state, 'audioOnlyVideoMuted', action.muted);
  234. }
  235. /**
  236. * Reduces a specific Redux action SET_LARGE_VIDEO_HD_STATUS of the feature
  237. * base/conference.
  238. *
  239. * @param {Object} state - The Redux state of the feature base/conference.
  240. * @param {Action} action - The Redux action SET_LARGE_VIDEO_HD_STATUS to
  241. * reduce.
  242. * @private
  243. * @returns {Object} The new state of the feature base/conference after the
  244. * reduction of the specified action.
  245. */
  246. function _setLargeVideoHDStatus(state, action) {
  247. return set(state, 'isLargeVideoHD', action.isLargeVideoHD);
  248. }
  249. /**
  250. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  251. *
  252. * @param {Object} state - The Redux state of the feature base/conference.
  253. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  254. * @private
  255. * @returns {Object} The new state of the feature base/conference after the
  256. * reduction of the specified action.
  257. */
  258. function _setPassword(state, { conference, method, password }) {
  259. switch (method) {
  260. case conference.join:
  261. if (state.passwordRequired === conference) {
  262. return 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,
  270. passwordRequired: undefined
  271. });
  272. }
  273. break;
  274. case conference.lock:
  275. return assign(state, {
  276. locked: password ? LOCKED_LOCALLY : undefined,
  277. 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. }