You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. import _ from 'lodash';
  2. import { CONFERENCE_INFO } from '../../conference/components/constants';
  3. import ReducerRegistry from '../redux/ReducerRegistry';
  4. import { equals } from '../redux/functions';
  5. import {
  6. CONFIG_WILL_LOAD,
  7. LOAD_CONFIG_ERROR,
  8. OVERWRITE_CONFIG,
  9. SET_CONFIG,
  10. UPDATE_CONFIG
  11. } from './actionTypes';
  12. import { IConfig } from './configType';
  13. // eslint-disable-next-line lines-around-comment
  14. // @ts-ignore
  15. import { _cleanupConfig } from './functions';
  16. declare let interfaceConfig: any;
  17. /**
  18. * The initial state of the feature base/config when executing in a
  19. * non-React Native environment. The mandatory configuration to be passed to
  20. * JitsiMeetJS#init(). The app will download config.js from the Jitsi Meet
  21. * deployment and take its values into account but the values below will be
  22. * enforced (because they are essential to the correct execution of the
  23. * application).
  24. *
  25. * @type {Object}
  26. */
  27. const INITIAL_NON_RN_STATE: IConfig = {
  28. };
  29. /**
  30. * The initial state of the feature base/config when executing in a React Native
  31. * environment. The mandatory configuration to be passed to JitsiMeetJS#init().
  32. * The app will download config.js from the Jitsi Meet deployment and take its
  33. * values into account but the values below will be enforced (because they are
  34. * essential to the correct execution of the application).
  35. *
  36. * @type {Object}
  37. */
  38. const INITIAL_RN_STATE: IConfig = {
  39. analytics: {},
  40. // FIXME The support for audio levels in lib-jitsi-meet polls the statistics
  41. // of WebRTC at a short interval multiple times a second. Unfortunately,
  42. // React Native is slow to fetch these statistics from the native WebRTC
  43. // API, through the React Native bridge and eventually to JavaScript.
  44. // Because the audio levels are of no interest to the mobile app, it is
  45. // fastest to merely disable them.
  46. disableAudioLevels: true,
  47. p2p: {
  48. disabledCodec: '',
  49. disableH264: false, // deprecated
  50. preferredCodec: 'H264',
  51. preferH264: true // deprecated
  52. }
  53. };
  54. /**
  55. * Mapping between old configs controlling the conference info headers visibility and the
  56. * new configs. Needed in order to keep backwards compatibility.
  57. */
  58. const CONFERENCE_HEADER_MAPPING: any = {
  59. hideConferenceTimer: [ 'conference-timer' ],
  60. hideConferenceSubject: [ 'subject' ],
  61. hideParticipantsStats: [ 'participants-count' ],
  62. hideRecordingLabel: [ 'recording' ]
  63. };
  64. export interface IConfigState extends IConfig {
  65. analysis?: {
  66. obfuscateRoomName?: boolean;
  67. };
  68. error?: Error;
  69. }
  70. ReducerRegistry.register<IConfigState>('features/base/config', (state = _getInitialState(), action): IConfigState => {
  71. switch (action.type) {
  72. case UPDATE_CONFIG:
  73. return _updateConfig(state, action);
  74. case CONFIG_WILL_LOAD:
  75. return {
  76. error: undefined,
  77. /**
  78. * The URL of the location associated with/configured by this
  79. * configuration.
  80. *
  81. * @type URL
  82. */
  83. locationURL: action.locationURL
  84. };
  85. case LOAD_CONFIG_ERROR:
  86. // XXX LOAD_CONFIG_ERROR is one of the settlement execution paths of
  87. // the asynchronous "loadConfig procedure/process" started with
  88. // CONFIG_WILL_LOAD. Due to the asynchronous nature of it, whoever
  89. // is settling the process needs to provide proof that they have
  90. // started it and that the iteration of the process being completed
  91. // now is still of interest to the app.
  92. if (state.locationURL === action.locationURL) {
  93. return {
  94. /**
  95. * The {@link Error} which prevented the loading of the
  96. * configuration of the associated {@code locationURL}.
  97. *
  98. * @type Error
  99. */
  100. error: action.error
  101. };
  102. }
  103. break;
  104. case SET_CONFIG:
  105. return _setConfig(state, action);
  106. case OVERWRITE_CONFIG:
  107. return {
  108. ...state,
  109. ...action.config
  110. };
  111. }
  112. return state;
  113. });
  114. /**
  115. * Gets the initial state of the feature base/config. The mandatory
  116. * configuration to be passed to JitsiMeetJS#init(). The app will download
  117. * config.js from the Jitsi Meet deployment and take its values into account but
  118. * the values below will be enforced (because they are essential to the correct
  119. * execution of the application).
  120. *
  121. * @returns {Object}
  122. */
  123. function _getInitialState() {
  124. return (
  125. navigator.product === 'ReactNative'
  126. ? INITIAL_RN_STATE
  127. : INITIAL_NON_RN_STATE);
  128. }
  129. /**
  130. * Reduces a specific Redux action SET_CONFIG of the feature
  131. * base/lib-jitsi-meet.
  132. *
  133. * @param {IConfig} state - The Redux state of the feature base/config.
  134. * @param {Action} action - The Redux action SET_CONFIG to reduce.
  135. * @private
  136. * @returns {Object} The new state after the reduction of the specified action.
  137. */
  138. function _setConfig(state: IConfig, { config }: { config: IConfig; }) {
  139. // eslint-disable-next-line no-param-reassign
  140. config = _translateLegacyConfig(config);
  141. const { audioQuality } = config;
  142. const hdAudioOptions = {};
  143. if (audioQuality?.stereo) {
  144. Object.assign(hdAudioOptions, {
  145. disableAP: true,
  146. enableNoAudioDetection: false,
  147. enableNoisyMicDetection: false,
  148. enableTalkWhileMuted: false
  149. });
  150. }
  151. const newState = _.merge(
  152. {},
  153. config,
  154. hdAudioOptions,
  155. { error: undefined },
  156. // The config of _getInitialState() is meant to override the config
  157. // downloaded from the Jitsi Meet deployment because the former contains
  158. // values that are mandatory.
  159. _getInitialState()
  160. );
  161. _cleanupConfig(newState);
  162. return equals(state, newState) ? state : newState;
  163. }
  164. /**
  165. * Processes the conferenceInfo object against the defaults.
  166. *
  167. * @param {IConfig} config - The old config.
  168. * @returns {Object} The processed conferenceInfo object.
  169. */
  170. function _getConferenceInfo(config: IConfig) {
  171. const { conferenceInfo } = config;
  172. if (conferenceInfo) {
  173. return {
  174. alwaysVisible: conferenceInfo.alwaysVisible ?? [ ...CONFERENCE_INFO.alwaysVisible ],
  175. autoHide: conferenceInfo.autoHide ?? [ ...CONFERENCE_INFO.autoHide ]
  176. };
  177. }
  178. return {
  179. ...CONFERENCE_INFO
  180. };
  181. }
  182. /**
  183. * Constructs a new config {@code Object}, if necessary, out of a specific
  184. * interface_config {@code Object} which is in the latest format supported by jitsi-meet.
  185. *
  186. * @param {Object} oldValue - The config {@code Object} which may or may not be
  187. * in the latest form supported by jitsi-meet and from which a new config
  188. * {@code Object} is to be constructed if necessary.
  189. * @returns {Object} A config {@code Object} which is in the latest format
  190. * supported by jitsi-meet.
  191. */
  192. function _translateInterfaceConfig(oldValue: IConfig) {
  193. const newValue = oldValue;
  194. if (!Array.isArray(oldValue.toolbarButtons)
  195. && typeof interfaceConfig === 'object' && Array.isArray(interfaceConfig.TOOLBAR_BUTTONS)) {
  196. newValue.toolbarButtons = interfaceConfig.TOOLBAR_BUTTONS;
  197. }
  198. if (!oldValue.toolbarConfig) {
  199. oldValue.toolbarConfig = {};
  200. }
  201. newValue.toolbarConfig = oldValue.toolbarConfig || {};
  202. if (typeof oldValue.toolbarConfig.alwaysVisible !== 'boolean'
  203. && typeof interfaceConfig === 'object'
  204. && typeof interfaceConfig.TOOLBAR_ALWAYS_VISIBLE === 'boolean') {
  205. newValue.toolbarConfig.alwaysVisible = interfaceConfig.TOOLBAR_ALWAYS_VISIBLE;
  206. }
  207. if (typeof oldValue.toolbarConfig.initialTimeout !== 'number'
  208. && typeof interfaceConfig === 'object'
  209. && typeof interfaceConfig.INITIAL_TOOLBAR_TIMEOUT === 'number') {
  210. newValue.toolbarConfig.initialTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  211. }
  212. if (typeof oldValue.toolbarConfig.timeout !== 'number'
  213. && typeof interfaceConfig === 'object'
  214. && typeof interfaceConfig.TOOLBAR_TIMEOUT === 'number') {
  215. newValue.toolbarConfig.timeout = interfaceConfig.TOOLBAR_TIMEOUT;
  216. }
  217. if (!oldValue.connectionIndicators
  218. && typeof interfaceConfig === 'object'
  219. && (interfaceConfig.hasOwnProperty('CONNECTION_INDICATOR_DISABLED')
  220. || interfaceConfig.hasOwnProperty('CONNECTION_INDICATOR_AUTO_HIDE_ENABLED')
  221. || interfaceConfig.hasOwnProperty('CONNECTION_INDICATOR_AUTO_HIDE_TIMEOUT'))) {
  222. newValue.connectionIndicators = {
  223. disabled: interfaceConfig.CONNECTION_INDICATOR_DISABLED,
  224. autoHide: interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED,
  225. autoHideTimeout: interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_TIMEOUT
  226. };
  227. }
  228. if (oldValue.disableModeratorIndicator === undefined
  229. && typeof interfaceConfig === 'object'
  230. && interfaceConfig.hasOwnProperty('DISABLE_FOCUS_INDICATOR')) {
  231. newValue.disableModeratorIndicator = interfaceConfig.DISABLE_FOCUS_INDICATOR;
  232. }
  233. if (oldValue.defaultLocalDisplayName === undefined
  234. && typeof interfaceConfig === 'object'
  235. && interfaceConfig.hasOwnProperty('DEFAULT_LOCAL_DISPLAY_NAME')) {
  236. newValue.defaultLocalDisplayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  237. }
  238. if (oldValue.defaultRemoteDisplayName === undefined
  239. && typeof interfaceConfig === 'object'
  240. && interfaceConfig.hasOwnProperty('DEFAULT_REMOTE_DISPLAY_NAME')) {
  241. newValue.defaultRemoteDisplayName = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  242. }
  243. if (oldValue.defaultLogoUrl === undefined) {
  244. if (typeof interfaceConfig === 'object'
  245. && interfaceConfig.hasOwnProperty('DEFAULT_LOGO_URL')) {
  246. newValue.defaultLogoUrl = interfaceConfig.DEFAULT_LOGO_URL;
  247. } else {
  248. newValue.defaultLogoUrl = 'images/watermark.svg';
  249. }
  250. }
  251. return newValue;
  252. }
  253. /**
  254. * Constructs a new config {@code Object}, if necessary, out of a specific
  255. * config {@code Object} which is in the latest format supported by jitsi-meet.
  256. * Such a translation from an old config format to a new/the latest config
  257. * format is necessary because the mobile app bundles jitsi-meet and
  258. * lib-jitsi-meet at build time and does not download them at runtime from the
  259. * deployment on which it will join a conference.
  260. *
  261. * @param {Object} oldValue - The config {@code Object} which may or may not be
  262. * in the latest form supported by jitsi-meet and from which a new config
  263. * {@code Object} is to be constructed if necessary.
  264. * @returns {Object} A config {@code Object} which is in the latest format
  265. * supported by jitsi-meet.
  266. */
  267. function _translateLegacyConfig(oldValue: IConfig) {
  268. const newValue = _translateInterfaceConfig(oldValue);
  269. // Translate deprecated config values to new config values.
  270. const filteredConferenceInfo = Object.keys(CONFERENCE_HEADER_MAPPING).filter(key => oldValue[key as keyof IConfig]);
  271. if (filteredConferenceInfo.length) {
  272. newValue.conferenceInfo = _getConferenceInfo(oldValue);
  273. filteredConferenceInfo.forEach(key => {
  274. newValue.conferenceInfo = oldValue.conferenceInfo ?? {};
  275. // hideRecordingLabel does not mean not render it at all, but autoHide it
  276. if (key === 'hideRecordingLabel') {
  277. newValue.conferenceInfo.alwaysVisible
  278. = (newValue.conferenceInfo?.alwaysVisible ?? [])
  279. .filter(c => !CONFERENCE_HEADER_MAPPING[key].includes(c));
  280. newValue.conferenceInfo.autoHide
  281. = _.union(newValue.conferenceInfo.autoHide, CONFERENCE_HEADER_MAPPING[key]);
  282. } else {
  283. newValue.conferenceInfo.alwaysVisible
  284. = (newValue.conferenceInfo.alwaysVisible ?? [])
  285. .filter(c => !CONFERENCE_HEADER_MAPPING[key].includes(c));
  286. newValue.conferenceInfo.autoHide
  287. = (newValue.conferenceInfo.autoHide ?? []).filter(c => !CONFERENCE_HEADER_MAPPING[key].includes(c));
  288. }
  289. });
  290. }
  291. newValue.prejoinConfig = oldValue.prejoinConfig || {};
  292. if (oldValue.hasOwnProperty('prejoinPageEnabled')
  293. && !newValue.prejoinConfig.hasOwnProperty('enabled')
  294. ) {
  295. newValue.prejoinConfig.enabled = oldValue.prejoinPageEnabled;
  296. }
  297. newValue.disabledSounds = newValue.disabledSounds || [];
  298. if (oldValue.disableJoinLeaveSounds) {
  299. newValue.disabledSounds.unshift('PARTICIPANT_LEFT_SOUND', 'PARTICIPANT_JOINED_SOUND');
  300. }
  301. if (oldValue.disableRecordAudioNotification) {
  302. newValue.disabledSounds.unshift(
  303. 'RECORDING_ON_SOUND',
  304. 'RECORDING_OFF_SOUND',
  305. 'LIVE_STREAMING_ON_SOUND',
  306. 'LIVE_STREAMING_OFF_SOUND'
  307. );
  308. }
  309. if (oldValue.disableIncomingMessageSound) {
  310. newValue.disabledSounds.unshift('INCOMING_MSG_SOUND');
  311. }
  312. if (oldValue.stereo || oldValue.opusMaxAverageBitrate) {
  313. newValue.audioQuality = {
  314. opusMaxAverageBitrate: oldValue.audioQuality?.opusMaxAverageBitrate ?? oldValue.opusMaxAverageBitrate,
  315. stereo: oldValue.audioQuality?.stereo ?? oldValue.stereo
  316. };
  317. }
  318. newValue.e2ee = newValue.e2ee || {};
  319. if (oldValue.e2eeLabels) {
  320. newValue.e2ee.e2eeLabels = oldValue.e2eeLabels;
  321. }
  322. newValue.defaultLocalDisplayName
  323. = newValue.defaultLocalDisplayName || 'me';
  324. if (oldValue.hideAddRoomButton) {
  325. newValue.breakoutRooms = {
  326. /* eslint-disable-next-line no-extra-parens */
  327. ...(newValue.breakoutRooms || {}),
  328. hideAddRoomButton: oldValue.hideAddRoomButton
  329. };
  330. }
  331. newValue.defaultRemoteDisplayName
  332. = newValue.defaultRemoteDisplayName || 'Fellow Jitster';
  333. newValue.transcription = newValue.transcription || {};
  334. if (oldValue.transcribingEnabled !== undefined) {
  335. newValue.transcription = {
  336. ...newValue.transcription,
  337. enabled: oldValue.transcribingEnabled
  338. };
  339. }
  340. if (oldValue.transcribeWithAppLanguage !== undefined) {
  341. newValue.transcription = {
  342. ...newValue.transcription,
  343. useAppLanguage: oldValue.transcribeWithAppLanguage
  344. };
  345. }
  346. if (oldValue.preferredTranscribeLanguage !== undefined) {
  347. newValue.transcription = {
  348. ...newValue.transcription,
  349. preferredLanguage: oldValue.preferredTranscribeLanguage
  350. };
  351. }
  352. if (oldValue.autoCaptionOnRecord !== undefined) {
  353. newValue.transcription = {
  354. ...newValue.transcription,
  355. autoCaptionOnRecord: oldValue.autoCaptionOnRecord
  356. };
  357. }
  358. newValue.recordingService = newValue.recordingService || {};
  359. if (oldValue.fileRecordingsServiceEnabled !== undefined
  360. && newValue.recordingService.enabled === undefined) {
  361. newValue.recordingService = {
  362. ...newValue.recordingService,
  363. enabled: oldValue.fileRecordingsServiceEnabled
  364. };
  365. }
  366. if (oldValue.fileRecordingsServiceSharingEnabled !== undefined
  367. && newValue.recordingService.sharingEnabled === undefined) {
  368. newValue.recordingService = {
  369. ...newValue.recordingService,
  370. sharingEnabled: oldValue.fileRecordingsServiceSharingEnabled
  371. };
  372. }
  373. newValue.liveStreaming = newValue.liveStreaming || {};
  374. // Migrate config.liveStreamingEnabled
  375. if (oldValue.liveStreamingEnabled !== undefined) {
  376. newValue.liveStreaming = {
  377. ...newValue.liveStreaming,
  378. enabled: oldValue.liveStreamingEnabled
  379. };
  380. }
  381. // Migrate interfaceConfig.LIVE_STREAMING_HELP_LINK
  382. if (oldValue.liveStreaming === undefined
  383. && typeof interfaceConfig === 'object'
  384. && interfaceConfig.hasOwnProperty('LIVE_STREAMING_HELP_LINK')) {
  385. newValue.liveStreaming = {
  386. ...newValue.liveStreaming,
  387. helpLink: interfaceConfig.LIVE_STREAMING_HELP_LINK
  388. };
  389. }
  390. return newValue;
  391. }
  392. /**
  393. * Updates the stored configuration with the given extra options.
  394. *
  395. * @param {Object} state - The Redux state of the feature base/config.
  396. * @param {Action} action - The Redux action to reduce.
  397. * @private
  398. * @returns {Object} The new state after the reduction of the specified action.
  399. */
  400. function _updateConfig(state: IConfig, { config }: { config: IConfig; }) {
  401. const newState = _.merge({}, state, config);
  402. _cleanupConfig(newState);
  403. return equals(state, newState) ? state : newState;
  404. }