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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /* eslint-disable import/order */
  2. // @ts-ignore
  3. import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
  4. // @ts-ignore
  5. import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';
  6. // @ts-ignore
  7. import { JitsiConferenceErrors } from '../lib-jitsi-meet';
  8. import { assign, set } from '../redux/functions';
  9. import ReducerRegistry from '../redux/ReducerRegistry';
  10. import {
  11. AUTH_STATUS_CHANGED,
  12. CONFERENCE_FAILED,
  13. CONFERENCE_JOINED,
  14. CONFERENCE_LEFT,
  15. CONFERENCE_LOCAL_SUBJECT_CHANGED,
  16. CONFERENCE_SUBJECT_CHANGED,
  17. CONFERENCE_TIMESTAMP_CHANGED,
  18. CONFERENCE_WILL_JOIN,
  19. CONFERENCE_WILL_LEAVE,
  20. LOCK_STATE_CHANGED,
  21. P2P_STATUS_CHANGED,
  22. SET_FOLLOW_ME,
  23. SET_OBFUSCATED_ROOM,
  24. SET_PASSWORD,
  25. SET_PENDING_SUBJECT_CHANGE,
  26. SET_ROOM,
  27. SET_START_MUTED_POLICY,
  28. SET_START_REACTIONS_MUTED
  29. } from './actionTypes';
  30. // @ts-ignore
  31. import { isRoomValid } from './functions';
  32. const DEFAULT_STATE = {
  33. conference: undefined,
  34. e2eeSupported: undefined,
  35. joining: undefined,
  36. leaving: undefined,
  37. locked: undefined,
  38. membersOnly: undefined,
  39. password: undefined,
  40. passwordRequired: undefined
  41. };
  42. export interface IConferenceState {
  43. authEnabled?: boolean|undefined;
  44. authLogin?: string|undefined;
  45. authRequired?: Object;
  46. conference: any|undefined;
  47. conferenceTimestamp?: number;
  48. e2eeSupported: boolean|undefined;
  49. followMeEnabled?: boolean;
  50. joining: Object|undefined;
  51. leaving: Object|undefined;
  52. localSubject?: string;
  53. locked: string|undefined;
  54. membersOnly: boolean|undefined;
  55. password: string|undefined;
  56. passwordRequired: boolean|undefined;
  57. pendingSubjectChange?: string;
  58. room?: Object;
  59. startReactionsMuted?: boolean;
  60. subject?: string;
  61. }
  62. /**
  63. * Listen for actions that contain the conference object, so that it can be
  64. * stored for use by other action creators.
  65. */
  66. ReducerRegistry.register(
  67. 'features/base/conference',
  68. (state: IConferenceState = DEFAULT_STATE, action: any) => {
  69. switch (action.type) {
  70. case AUTH_STATUS_CHANGED:
  71. return _authStatusChanged(state, action);
  72. case CONFERENCE_FAILED:
  73. return _conferenceFailed(state, action);
  74. case CONFERENCE_JOINED:
  75. return _conferenceJoined(state, action);
  76. case CONFERENCE_SUBJECT_CHANGED:
  77. return set(state, 'subject', action.subject);
  78. case CONFERENCE_LOCAL_SUBJECT_CHANGED:
  79. return set(state, 'localSubject', action.localSubject);
  80. case CONFERENCE_TIMESTAMP_CHANGED:
  81. return set(state, 'conferenceTimestamp', action.conferenceTimestamp);
  82. case CONFERENCE_LEFT:
  83. case CONFERENCE_WILL_LEAVE:
  84. return _conferenceLeftOrWillLeave(state, action);
  85. case CONFERENCE_WILL_JOIN:
  86. return _conferenceWillJoin(state, action);
  87. case CONNECTION_WILL_CONNECT:
  88. return set(state, 'authRequired', undefined);
  89. case LOCK_STATE_CHANGED:
  90. return _lockStateChanged(state, action);
  91. case P2P_STATUS_CHANGED:
  92. return _p2pStatusChanged(state, action);
  93. case SET_FOLLOW_ME:
  94. return set(state, 'followMeEnabled', action.enabled);
  95. case SET_START_REACTIONS_MUTED:
  96. return set(state, 'startReactionsMuted', action.muted);
  97. case SET_LOCATION_URL:
  98. return set(state, 'room', undefined);
  99. case SET_OBFUSCATED_ROOM:
  100. return { ...state,
  101. obfuscatedRoom: action.obfuscatedRoom,
  102. obfuscatedRoomSource: action.obfuscatedRoomSource
  103. };
  104. case SET_PASSWORD:
  105. return _setPassword(state, action);
  106. case SET_PENDING_SUBJECT_CHANGE:
  107. return set(state, 'pendingSubjectChange', action.subject);
  108. case SET_ROOM:
  109. return _setRoom(state, action);
  110. case SET_START_MUTED_POLICY:
  111. return {
  112. ...state,
  113. startAudioMutedPolicy: action.startAudioMutedPolicy,
  114. startVideoMutedPolicy: action.startVideoMutedPolicy
  115. };
  116. }
  117. return state;
  118. });
  119. /**
  120. * Reduces a specific Redux action AUTH_STATUS_CHANGED of the feature
  121. * base/conference.
  122. *
  123. * @param {Object} state - The Redux state of the feature base/conference.
  124. * @param {Action} action - The Redux action AUTH_STATUS_CHANGED to reduce.
  125. * @private
  126. * @returns {Object} The new state of the feature base/conference after the
  127. * reduction of the specified action.
  128. */
  129. function _authStatusChanged(state: any, { authEnabled, authLogin }: {authEnabled: boolean, authLogin: string}) {
  130. return assign(state, {
  131. authEnabled,
  132. authLogin
  133. });
  134. }
  135. /**
  136. * Reduces a specific Redux action CONFERENCE_FAILED of the feature
  137. * base/conference.
  138. *
  139. * @param {Object} state - The Redux state of the feature base/conference.
  140. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  141. * @private
  142. * @returns {Object} The new state of the feature base/conference after the
  143. * reduction of the specified action.
  144. */
  145. function _conferenceFailed(state: any, { conference, error }: {conference: Object, error: any}) {
  146. // The current (similar to getCurrentConference in
  147. // base/conference/functions.any.js) conference which is joining or joined:
  148. const conference_ = state.conference || state.joining;
  149. if (conference_ && conference_ !== conference) {
  150. return state;
  151. }
  152. let authRequired;
  153. let membersOnly;
  154. let passwordRequired;
  155. switch (error.name) {
  156. case JitsiConferenceErrors.AUTHENTICATION_REQUIRED:
  157. authRequired = conference;
  158. break;
  159. case JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED:
  160. case JitsiConferenceErrors.MEMBERS_ONLY_ERROR:
  161. membersOnly = conference;
  162. break;
  163. case JitsiConferenceErrors.PASSWORD_REQUIRED:
  164. passwordRequired = conference;
  165. break;
  166. }
  167. return assign(state, {
  168. authRequired,
  169. conference: undefined,
  170. e2eeSupported: undefined,
  171. error,
  172. joining: undefined,
  173. leaving: undefined,
  174. /**
  175. * The indicator of how the conference/room is locked. If falsy, the
  176. * conference/room is unlocked; otherwise, it's either
  177. * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
  178. *
  179. * @type {string}
  180. */
  181. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  182. membersOnly,
  183. password: undefined,
  184. /**
  185. * The JitsiConference instance which requires a password to join.
  186. *
  187. * @type {JitsiConference}
  188. */
  189. passwordRequired
  190. });
  191. }
  192. /**
  193. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  194. * base/conference.
  195. *
  196. * @param {Object} state - The Redux state of the feature base/conference.
  197. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  198. * @private
  199. * @returns {Object} The new state of the feature base/conference after the
  200. * reduction of the specified action.
  201. */
  202. function _conferenceJoined(state: any, { conference }: {conference: any}) {
  203. // FIXME The indicator which determines whether a JitsiConference is locked
  204. // i.e. password-protected is private to lib-jitsi-meet. However, the
  205. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  206. // with a password.
  207. // FIXME Technically JitsiConference.room is a private field.
  208. const locked = conference.room && conference.room.locked ? LOCKED_REMOTELY : undefined;
  209. return assign(state, {
  210. authRequired: undefined,
  211. /**
  212. * The JitsiConference instance represented by the Redux state of the
  213. * feature base/conference.
  214. *
  215. * @type {JitsiConference}
  216. */
  217. conference,
  218. e2eeSupported: conference.isE2EESupported(),
  219. joining: undefined,
  220. membersOnly: undefined,
  221. leaving: undefined,
  222. /**
  223. * The indicator which determines whether the conference is locked.
  224. *
  225. * @type {boolean}
  226. */
  227. locked,
  228. passwordRequired: undefined
  229. });
  230. }
  231. /**
  232. * Reduces a specific redux action {@link CONFERENCE_LEFT} or
  233. * {@link CONFERENCE_WILL_LEAVE} for the feature base/conference.
  234. *
  235. * @param {Object} state - The redux state of the feature base/conference.
  236. * @param {Action} action - The redux action {@code CONFERENCE_LEFT} or
  237. * {@code CONFERENCE_WILL_LEAVE} to reduce.
  238. * @private
  239. * @returns {Object} The next/new state of the feature base/conference after the
  240. * reduction of the specified action.
  241. */
  242. function _conferenceLeftOrWillLeave(state: any, { conference, type }: {conference: Object, type: string}) {
  243. const nextState = { ...state };
  244. // The redux action CONFERENCE_LEFT is the last time that we should be
  245. // hearing from a JitsiConference instance.
  246. //
  247. // The redux action CONFERENCE_WILL_LEAVE represents the order of the user
  248. // to leave a JitsiConference instance. From the user's perspective, there's
  249. // no going back (with respect to the instance itself). The app will perform
  250. // due clean-up like leaving the associated room, but the instance is no
  251. // longer the focus of the attention of the user and, consequently, the app.
  252. for (const p in state) {
  253. if (state[p] === conference) {
  254. nextState[p] = undefined;
  255. switch (p) {
  256. case 'conference':
  257. case 'passwordRequired':
  258. // XXX Clear/unset locked & password for a conference which has
  259. // been LOCKED_LOCALLY or LOCKED_REMOTELY.
  260. delete nextState.locked;
  261. delete nextState.password;
  262. break;
  263. }
  264. }
  265. }
  266. if (type === CONFERENCE_WILL_LEAVE) {
  267. // A CONFERENCE_WILL_LEAVE is of further consequence only if it is
  268. // expected i.e. if the specified conference is joining or joined.
  269. if (conference === state.joining || conference === state.conference) {
  270. /**
  271. * The JitsiConference instance which is currently in the process of
  272. * being left.
  273. *
  274. * @type {JitsiConference}
  275. */
  276. nextState.leaving = conference;
  277. }
  278. }
  279. return nextState;
  280. }
  281. /**
  282. * Reduces a specific Redux action CONFERENCE_WILL_JOIN 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 CONFERENCE_WILL_JOIN 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 _conferenceWillJoin(state: any, { conference }: {conference: Object}) {
  292. return assign(state, {
  293. error: undefined,
  294. joining: conference
  295. });
  296. }
  297. /**
  298. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  299. * base/conference.
  300. *
  301. * @param {Object} state - The Redux state of the feature base/conference.
  302. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  303. * @private
  304. * @returns {Object} The new state of the feature base/conference after the
  305. * reduction of the specified action.
  306. */
  307. function _lockStateChanged(state: any, { conference, locked }: {conference: Object, locked: boolean}) {
  308. if (state.conference !== conference) {
  309. return state;
  310. }
  311. return assign(state, {
  312. locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
  313. password: locked ? state.password : undefined
  314. });
  315. }
  316. /**
  317. * Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
  318. * base/conference.
  319. *
  320. * @param {Object} state - The Redux state of the feature base/conference.
  321. * @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
  322. * @private
  323. * @returns {Object} The new state of the feature base/conference after the
  324. * reduction of the specified action.
  325. */
  326. function _p2pStatusChanged(state: any, action: any) {
  327. return set(state, 'p2p', action.p2p);
  328. }
  329. /**
  330. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  331. *
  332. * @param {Object} state - The Redux state of the feature base/conference.
  333. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  334. * @private
  335. * @returns {Object} The new state of the feature base/conference after the
  336. * reduction of the specified action.
  337. */
  338. function _setPassword(state: any, { conference, method, password }
  339. : {conference: any, method: Object, password: string}) {
  340. switch (method) {
  341. case conference.join:
  342. return assign(state, {
  343. // 1. The JitsiConference which transitions away from
  344. // passwordRequired MUST remain in the redux state
  345. // features/base/conference until it transitions into
  346. // conference; otherwise, there is a span of time during which
  347. // the redux state does not even know that there is a
  348. // JitsiConference whatsoever.
  349. //
  350. // 2. The redux action setPassword will attempt to join the
  351. // JitsiConference so joining is an appropriate transitional
  352. // redux state.
  353. //
  354. // 3. The redux action setPassword will perform the same check
  355. // before it proceeds with the re-join.
  356. joining: state.conference ? state.joining : conference,
  357. locked: LOCKED_REMOTELY,
  358. /**
  359. * The password with which the conference is to be joined.
  360. *
  361. * @type {string}
  362. */
  363. password
  364. });
  365. case conference.lock:
  366. return assign(state, {
  367. locked: password ? LOCKED_LOCALLY : undefined,
  368. password
  369. });
  370. }
  371. return state;
  372. }
  373. /**
  374. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  375. *
  376. * @param {Object} state - The Redux state of the feature base/conference.
  377. * @param {Action} action - The Redux action SET_ROOM to reduce.
  378. * @private
  379. * @returns {Object} The new state of the feature base/conference after the
  380. * reduction of the specified action.
  381. */
  382. function _setRoom(state: any, action: any) {
  383. let { room } = action;
  384. if (!isRoomValid(room)) {
  385. // Technically, there are multiple values which don't represent valid
  386. // room names. Practically, each of them is as bad as the rest of them
  387. // because we can't use any of them to join a conference.
  388. room = undefined;
  389. }
  390. /**
  391. * The name of the room of the conference (to be) joined.
  392. *
  393. * @type {string}
  394. */
  395. return assign(state, {
  396. error: undefined,
  397. room
  398. });
  399. }