Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.ts 17KB

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