選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

functions.any.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. // @flow
  2. import _ from 'lodash';
  3. import { _CONFIG_STORE_PREFIX } from './constants';
  4. import parseURLParams from './parseURLParams';
  5. declare var $: Object;
  6. /**
  7. * The config keys to whitelist, the keys that can be overridden.
  8. * Currently we can only whitelist the first part of the properties, like
  9. * 'p2p.useStunTurn' and 'p2p.enabled' we whitelist all p2p options.
  10. * The whitelist is used only for config.js.
  11. *
  12. * @private
  13. * @type Array
  14. */
  15. const WHITELISTED_KEYS = [
  16. '_desktopSharingSourceDevice',
  17. '_peerConnStatusOutOfLastNTimeout',
  18. '_peerConnStatusRtcMuteTimeout',
  19. 'abTesting',
  20. 'analytics.disabled',
  21. 'autoRecord',
  22. 'autoRecordToken',
  23. 'avgRtpStatsN',
  24. 'callFlowsEnabled',
  25. 'callStatsConfIDNamespace',
  26. 'callStatsID',
  27. 'callStatsSecret',
  28. /**
  29. * The display name of the CallKit call representing the conference/meeting
  30. * associated with this config.js including while the call is ongoing in the
  31. * UI presented by CallKit and in the system-wide call history. The property
  32. * is meant for use cases in which the room name is not desirable as a
  33. * display name for CallKit purposes and the desired display name is not
  34. * provided in the form of a JWT callee. As the value is associated with a
  35. * conference/meeting, the value makes sense not as a deployment-wide
  36. * configuration, only as a runtime configuration override/overwrite
  37. * provided by, for example, Jitsi Meet SDK for iOS.
  38. *
  39. * @type string
  40. */
  41. 'callDisplayName',
  42. /**
  43. * The handle
  44. * ({@link https://developer.apple.com/documentation/callkit/cxhandle}) of
  45. * the CallKit call representing the conference/meeting associated with this
  46. * config.js. The property is meant for use cases in which the room URL is
  47. * not desirable as the handle for CallKit purposes. As the value is
  48. * associated with a conference/meeting, the value makes sense not as a
  49. * deployment-wide configuration, only as a runtime configuration
  50. * override/overwrite provided by, for example, Jitsi Meet SDK for iOS.
  51. *
  52. * @type string
  53. */
  54. 'callHandle',
  55. /**
  56. * The UUID of the CallKit call representing the conference/meeting
  57. * associated with this config.js. The property is meant for use cases in
  58. * which Jitsi Meet is to work with a CallKit call created outside of Jitsi
  59. * Meet and to be adopted by Jitsi Meet such as, for example, an incoming
  60. * and/or outgoing CallKit call created by Jitsi Meet SDK for iOS
  61. * clients/consumers prior to giving control to Jitsi Meet. As the value is
  62. * associated with a conference/meeting, the value makes sense not as a
  63. * deployment-wide configuration, only as a runtime configuration
  64. * override/overwrite provided by, for example, Jitsi Meet SDK for iOS.
  65. *
  66. * @type string
  67. */
  68. 'callUUID',
  69. 'channelLastN',
  70. 'constraints',
  71. 'debug',
  72. 'debugAudioLevels',
  73. 'defaultLanguage',
  74. 'desktopSharingChromeDisabled',
  75. 'desktopSharingChromeExtId',
  76. 'desktopSharingChromeMinExtVersion',
  77. 'desktopSharingChromeSources',
  78. 'desktopSharingFrameRate',
  79. 'desktopSharingFirefoxDisabled',
  80. 'desktopSharingSources',
  81. 'disable1On1Mode',
  82. 'disableAEC',
  83. 'disableAGC',
  84. 'disableAP',
  85. 'disableAudioLevels',
  86. 'disableDeepLinking',
  87. 'disableH264',
  88. 'disableHPF',
  89. 'disableNS',
  90. 'disableRemoteControl',
  91. 'disableRtx',
  92. 'disableSuspendVideo',
  93. 'displayJids',
  94. 'e2eping',
  95. 'enableDisplayNameInStats',
  96. 'enableLayerSuspension',
  97. 'enableLipSync',
  98. 'disableLocalVideoFlip',
  99. 'enableRemb',
  100. 'enableStatsID',
  101. 'enableTalkWhileMuted',
  102. 'enableTcc',
  103. 'etherpad_base',
  104. 'failICE',
  105. 'fileRecordingsEnabled',
  106. 'firefox_fake_device',
  107. 'forceJVB121Ratio',
  108. 'gatherStats',
  109. 'googleApiApplicationClientID',
  110. 'hiddenDomain',
  111. 'hosts',
  112. 'iAmRecorder',
  113. 'iAmSipGateway',
  114. 'iceTransportPolicy',
  115. 'ignoreStartMuted',
  116. 'liveStreamingEnabled',
  117. 'localRecording',
  118. 'minParticipants',
  119. 'nick',
  120. 'openBridgeChannel',
  121. 'p2p',
  122. 'preferH264',
  123. 'requireDisplayName',
  124. 'resolution',
  125. 'startAudioMuted',
  126. 'startAudioOnly',
  127. 'startBitrate',
  128. 'startSilent',
  129. 'startScreenSharing',
  130. 'startVideoMuted',
  131. 'startWithAudioMuted',
  132. 'startWithVideoMuted',
  133. 'subject',
  134. 'testing',
  135. 'useIPv6',
  136. 'useNicks',
  137. 'useStunTurn',
  138. 'webrtcIceTcpDisable',
  139. 'webrtcIceUdpDisable'
  140. ];
  141. const logger = require('jitsi-meet-logger').getLogger(__filename);
  142. // XXX The functions getRoomName and parseURLParams are split out of
  143. // functions.js because they are bundled in both app.bundle and
  144. // do_external_connect, webpack 1 does not support tree shaking, and we don't
  145. // want all functions to be bundled in do_external_connect.
  146. export { default as getRoomName } from './getRoomName';
  147. export { parseURLParams };
  148. /**
  149. * Promise wrapper on obtain config method. When HttpConfigFetch will be moved
  150. * to React app it's better to use load config instead.
  151. *
  152. * @param {string} location - URL of the domain from which the config is to be
  153. * obtained.
  154. * @param {string} room - Room name.
  155. * @private
  156. * @returns {Promise<void>}
  157. */
  158. export function obtainConfig(location: string, room: string): Promise<void> {
  159. return new Promise((resolve, reject) =>
  160. _obtainConfig(location, room, (success, error) => {
  161. success ? resolve() : reject(error);
  162. })
  163. );
  164. }
  165. /**
  166. * Sends HTTP POST request to specified {@code endpoint}. In request the name
  167. * of the room is included in JSON format:
  168. * {
  169. * "rooomName": "someroom12345"
  170. * }.
  171. *
  172. * @param {string} endpoint - The name of HTTP endpoint to which to send
  173. * the HTTP POST request.
  174. * @param {string} roomName - The name of the conference room for which config
  175. * is requested.
  176. * @param {Function} complete - The callback to invoke upon success or failure.
  177. * @returns {void}
  178. */
  179. function _obtainConfig(endpoint: string, roomName: string, complete: Function) {
  180. logger.info(`Send config request to ${endpoint} for room: ${roomName}`);
  181. $.ajax(
  182. endpoint,
  183. {
  184. contentType: 'application/json',
  185. data: JSON.stringify({ roomName }),
  186. dataType: 'json',
  187. method: 'POST',
  188. error(jqXHR, textStatus, errorThrown) {
  189. logger.error('Get config error: ', jqXHR, errorThrown);
  190. complete(false, `Get config response status: ${textStatus}`);
  191. },
  192. success(data) {
  193. const { config, interfaceConfig, loggingConfig } = window;
  194. try {
  195. overrideConfigJSON(
  196. config, interfaceConfig, loggingConfig,
  197. data);
  198. complete(true);
  199. } catch (e) {
  200. logger.error('Parse config error: ', e);
  201. complete(false, e);
  202. }
  203. }
  204. }
  205. );
  206. }
  207. /* eslint-disable max-params, no-shadow */
  208. /**
  209. * Overrides JSON properties in {@code config} and
  210. * {@code interfaceConfig} Objects with the values from {@code newConfig}.
  211. * Overrides only the whitelisted keys.
  212. *
  213. * @param {Object} config - The config Object in which we'll be overriding
  214. * properties.
  215. * @param {Object} interfaceConfig - The interfaceConfig Object in which we'll
  216. * be overriding properties.
  217. * @param {Object} loggingConfig - The loggingConfig Object in which we'll be
  218. * overriding properties.
  219. * @param {Object} json - Object containing configuration properties.
  220. * Destination object is selected based on root property name:
  221. * {
  222. * config: {
  223. * // config.js properties here
  224. * },
  225. * interfaceConfig: {
  226. * // interface_config.js properties here
  227. * },
  228. * loggingConfig: {
  229. * // logging_config.js properties here
  230. * }
  231. * }.
  232. * @returns {void}
  233. */
  234. export function overrideConfigJSON(
  235. config: ?Object, interfaceConfig: ?Object, loggingConfig: ?Object,
  236. json: Object) {
  237. for (const configName of Object.keys(json)) {
  238. let configObj;
  239. if (configName === 'config') {
  240. configObj = config;
  241. } else if (configName === 'interfaceConfig') {
  242. configObj = interfaceConfig;
  243. } else if (configName === 'loggingConfig') {
  244. configObj = loggingConfig;
  245. }
  246. if (configObj) {
  247. const configJSON
  248. = _getWhitelistedJSON(configName, json[configName]);
  249. if (!_.isEmpty(configJSON)) {
  250. logger.info(
  251. `Extending ${configName} with: ${
  252. JSON.stringify(configJSON)}`);
  253. // eslint-disable-next-line arrow-body-style
  254. _.mergeWith(configObj, configJSON, (oldValue, newValue) => {
  255. // XXX We don't want to merge the arrays, we want to
  256. // overwrite them.
  257. return Array.isArray(oldValue) ? newValue : undefined;
  258. });
  259. }
  260. }
  261. }
  262. }
  263. /* eslint-enable max-params, no-shadow */
  264. /**
  265. * Whitelist only config.js, skips this for others configs
  266. * (interfaceConfig, loggingConfig).
  267. * Only extracts overridden values for keys we allow to be overridden.
  268. *
  269. * @param {string} configName - The config name, one of config,
  270. * interfaceConfig, loggingConfig.
  271. * @param {Object} configJSON - The object with keys and values to override.
  272. * @private
  273. * @returns {Object} - The result object only with the keys
  274. * that are whitelisted.
  275. */
  276. function _getWhitelistedJSON(configName, configJSON) {
  277. if (configName !== 'config') {
  278. return configJSON;
  279. }
  280. return _.pick(configJSON, WHITELISTED_KEYS);
  281. }
  282. /**
  283. * Restores a Jitsi Meet config.js from {@code localStorage} if it was
  284. * previously downloaded from a specific {@code baseURL} and stored with
  285. * {@link storeConfig}.
  286. *
  287. * @param {string} baseURL - The base URL from which the config.js was
  288. * previously downloaded and stored with {@code storeConfig}.
  289. * @returns {?Object} The Jitsi Meet config.js which was previously downloaded
  290. * from {@code baseURL} and stored with {@code storeConfig} if it was restored;
  291. * otherwise, {@code undefined}.
  292. */
  293. export function restoreConfig(baseURL: string): ?Object {
  294. let storage;
  295. const key = `${_CONFIG_STORE_PREFIX}/${baseURL}`;
  296. try {
  297. // XXX Even reading the property localStorage of window may throw an
  298. // error (which is user agent-specific behavior).
  299. storage = window.localStorage;
  300. const config = storage.getItem(key);
  301. if (config) {
  302. return JSON.parse(config) || undefined;
  303. }
  304. } catch (e) {
  305. // Somehow incorrect data ended up in the storage. Clean it up.
  306. storage && storage.removeItem(key);
  307. }
  308. return undefined;
  309. }
  310. /* eslint-disable max-params */
  311. /**
  312. * Inspects the hash part of the location URI and overrides values specified
  313. * there in the corresponding config objects given as the arguments. The syntax
  314. * is: {@code https://server.com/room#config.debug=true
  315. * &interfaceConfig.showButton=false&loggingConfig.something=1}.
  316. *
  317. * In the hash part each parameter will be parsed to JSON and then the root
  318. * object will be matched with the corresponding config object given as the
  319. * argument to this function.
  320. *
  321. * @param {Object} config - This is the general config.
  322. * @param {Object} interfaceConfig - This is the interface config.
  323. * @param {Object} loggingConfig - The logging config.
  324. * @param {URI} location - The new location to which the app is navigating to.
  325. * @returns {void}
  326. */
  327. export function setConfigFromURLParams(
  328. config: ?Object,
  329. interfaceConfig: ?Object,
  330. loggingConfig: ?Object,
  331. location: Object) {
  332. const params = parseURLParams(location);
  333. const json = {};
  334. // At this point we have:
  335. // params = {
  336. // "config.disableAudioLevels": false,
  337. // "config.channelLastN": -1,
  338. // "interfaceConfig.APP_NAME": "Jitsi Meet"
  339. // }
  340. // We want to have:
  341. // json = {
  342. // config: {
  343. // "disableAudioLevels": false,
  344. // "channelLastN": -1
  345. // },
  346. // interfaceConfig: {
  347. // "APP_NAME": "Jitsi Meet"
  348. // }
  349. // }
  350. config && (json.config = {});
  351. interfaceConfig && (json.interfaceConfig = {});
  352. loggingConfig && (json.loggingConfig = {});
  353. for (const param of Object.keys(params)) {
  354. let base = json;
  355. const names = param.split('.');
  356. const last = names.pop();
  357. for (const name of names) {
  358. base = base[name] = base[name] || {};
  359. }
  360. base[last] = params[param];
  361. }
  362. overrideConfigJSON(config, interfaceConfig, loggingConfig, json);
  363. }
  364. /* eslint-enable max-params */