Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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