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

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