Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
move username generator to utils
isymchychc89c9e78ff3d
diff --git a/modules/settings/Settings.js b/modules/settings/Settings.jsindex 0050645cb7..5cb692aca9 100644--- a/modules/settings/Settings.js+++ b/modules/settings/Settings.js@@ -1,4 +1,4 @@-var UsernameGenerator = require('../statistics/UsernameGenerator');+var UsernameGenerator = require('../util/UsernameGenerator');var email = '';var displayName = '';@@ -31,7 +31,8 @@ if (supportsLocalStorage()) {}if (!window.localStorage.callStatsUID) {window.localStorage.callStatsUID = UsernameGenerator.generateUsername();- console.log('generated callstats uid', window.localStorage.callStatsUID);+ console.log('generated callstats uid',+ window.localStorage.callStatsUID);}userId = window.localStorage.jitsiMeetId || '';callStatsUID = window.localStorage.callStatsUID;diff --git a/modules/util/RandomUtil.js b/modules/util/RandomUtil.jsindex 379480e8a4..48d13f4cd7 100644--- a/modules/util/RandomUtil.js+++ b/modules/util/RandomUtil.js@@ -1,13 +1,51 @@+/**+ * @const+ */+var ALPHANUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';/**- * Generates random hex number within the range [min, max]+ * Generates random int within the range [min, max]+ * @param min the minimum value for the generated number* @param max the maximum value for the generated number+ * @returns random int number+ */+function randomInt(min, max) {+ return Math.floor(Math.random() * (max - min + 1)) + min;+}++/**+ * Get random element from array or string.+ * @param {Array|string} arr source+ * @returns array element or string character+ */+function randomElement(arr) {+ return arr[randomInt(0, arr.length -1)];+}++/**+ * Generate random alphanumeric string.+ * @param {number} length expected string length+ * @returns {string} random string of specified length+ */+function randomAlphanumStr(length) {+ var result = '';++ for (var i = 0; i < length; i += 1) {+ result += randomElement(ALPHANUM);+ }++ return result;+}++/**+ * Generates random hex number within the range [min, max]* @param min the minimum value for the generated number+ * @param max the maximum value for the generated number* @returns random hex number*/function rangeRandomHex(min, max){- return Math.floor(Math.random() * (max - min) + min).toString(16);+ return randomInt(min, max).toString(16);}/**diff --git a/modules/statistics/UsernameGenerator.js b/modules/util/UsernameGenerator.jssimilarity index 97%rename from modules/statistics/UsernameGenerator.jsrename to modules/util/UsernameGenerator.jsindex e2cd222583..06a09471d3 100644--- a/modules/statistics/UsernameGenerator.js+++ b/modules/util/UsernameGenerator.js@@ -1,5 +1,8 @@+var RandomUtil = require('./RandomUtil');+/**- * from faker.js - Copyright (c) 2014-2015 Matthew Bergman & Marak Squires, MIT License+ * from faker.js - Copyright (c) 2014-2015 Matthew Bergman & Marak Squires+ * MIT License* http://github.com/marak/faker.js/** @const@@ -410,55 +413,13 @@ var names = ["Zora", "Zula"];-/**- * @const- */-var suffixChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';---/**- * Returns a random integer between min (inclusive) and max (inclusive).- */-function getRandomInt(min, max) {- return Math.floor(Math.random() * (max - min + 1)) + min;-}---/**- * Get random element from array or string.- *- * @param {Array|string} arr source- *- * @returns array element or string character- */-function getRandomElement(arr) {- return arr[getRandomInt(0, arr.length -1)];-}--/**- * Generate random alphanumeric string.- *- * @param {number} length expected string length- *- * @returns {string} random string of specified length- */-function generateAlphanumStr(length) {- var result = '';-- for (var i = 0; i < length; i += 1) {- result += getRandomElement(suffixChars);- }-- return result;-}-/*** Generate random username.* @returns {string} random username*/function generateUsername () {- var name = getRandomElement(names);- var suffix = generateAlphanumStr(3);+ var name = RandomUtil.randomElement(names);+ var suffix = RandomUtil.randomAlphanumStr(3);return name + '-' + suffix;}