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

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