Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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