Skip to content

Commit

Permalink
Rewrite with ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
idaynatovichatlassian authored and lyubomir committed Dec 9, 2016
1 parent 1cc2b38 commit 4584d89
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 220 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const LogCollector = Logger.LogCollector;
import JitsiMeetLogStorage from "./modules/util/JitsiMeetLogStorage";

import URLProcessor from "./modules/config/URLProcessor";
import RoomnameGenerator from './modules/util/RoomnameGenerator';
import { generateRoomWithoutSeparator } from './modules/util/RoomnameGenerator';

import UI from "./modules/UI/UI";
import settings from "./modules/settings/Settings";
Expand Down Expand Up @@ -75,7 +75,7 @@ function buildRoomName () {
let roomName = getRoomName();

if(!roomName) {
let word = RoomnameGenerator.generateRoomWithoutSeparator();
let word = generateRoomWithoutSeparator();
roomName = word.toLowerCase();
let historyURL = window.location.href + word;
//Trying to push state with current URL + roomName
Expand Down
5 changes: 2 additions & 3 deletions modules/UI/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SettingsMenu from "./side_pannels/settings/SettingsMenu";
import Profile from "./side_pannels/profile/Profile";
import Settings from "./../settings/Settings";
import RingOverlay from "./ring_overlay/RingOverlay";
import RandomUtil from "../util/RandomUtil";
import { randomInt } from "../util/RandomUtil";
import UIErrors from './UIErrors';
import { debounce } from "../util/helpers";

Expand Down Expand Up @@ -1100,8 +1100,7 @@ UI.notifyFocusDisconnected = function (focus, retrySec) {
*/
UI.showPageReloadOverlay = function (isNetworkFailure, reason) {
// Reload the page after 10 - 30 seconds
PageReloadOverlay.show(
10 + RandomUtil.randomInt(0, 20), isNetworkFailure, reason);
PageReloadOverlay.show(10 + randomInt(0, 20), isNetworkFailure, reason);
};

/**
Expand Down
9 changes: 5 additions & 4 deletions modules/UI/welcome_page/WelcomePage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* global $, interfaceConfig, APP */
var animateTimeout, updateTimeout;

var RoomnameGenerator = require("../../util/RoomnameGenerator");
import UIUtil from "../util/UIUtil";
import { generateRoomWithoutSeparator } from '../../util/RoomnameGenerator';
import UIUtil from '../util/UIUtil';

var animateTimeout, updateTimeout;

function enter_room() {
var val = $("#enter_room_field").val();
Expand All @@ -23,7 +24,7 @@ function animate(word) {
}

function update_roomname() {
var word = RoomnameGenerator.generateRoomWithoutSeparator();
var word = generateRoomWithoutSeparator();
$("#enter_room_field").attr("room_name", word);
$("#enter_room_field").attr("placeholder", "");
clearTimeout(animateTimeout);
Expand Down
105 changes: 57 additions & 48 deletions modules/util/RandomUtil.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,82 @@
/**
* Alphanumeric characters.
* @const
*/
var ALPHANUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const ALPHANUM
= '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

/**
* Hexadecimal digits.
* Hexadecimal digit characters.
* @const
*/
var HEX_DIGITS = '0123456789abcdef';
const HEX_DIGITS = '0123456789abcdef';

/**
* 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
* Generate a string with random alphanumeric characters with a specific length.
*
* @param {number} length - The length of the string to return.
* @returns {string} A string of random alphanumeric characters with the
* specified length.
*/
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
export function randomAlphanumString(length) {
return _randomString(length, ALPHANUM);
}

/**
* Get random element from array or string.
* @param {Array|string} arr source
* @returns array element or string character
* Get random element of array or string.
*
* @param {Array|string} arr - Source.
* @returns {Array|string} Array element or string character.
*/
function randomElement(arr) {
return arr[randomInt(0, arr.length -1)];
export 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
* Returns a random hex digit.
*
* @returns {Array|string}
*/
function randomAlphanumStr(length) {
var result = '';
export function randomHexDigit() {
return randomElement(HEX_DIGITS);
}

for (var i = 0; i < length; i += 1) {
result += randomElement(ALPHANUM);
}
/**
* Generates a string of random hexadecimal digits with a specific length.
*
* @param {number} length - The length of the string to return.
* @returns {string} A string of random hexadecimal digits with the specified
* length.
*/
export function randomHexString(length) {
return _randomString(length, HEX_DIGITS);
}

return result;
/**
* Generates random int within the range [min, max].
*
* @param {number} min - The minimum value for the generated number.
* @param {number} max - The maximum value for the generated number.
* @returns {number} Random int number.
*/
export function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
* Exported interface.
* Generates a string of random characters with a specific length.
*
* @param {number} length - The length of the string to return.
* @param {string} characters - The characters from which the returned string is
* to be constructed.
* @returns {string} A string of random characters with the specified length.
*/
var RandomUtil = {
/**
* Returns a random hex digit.
* @returns {*}
*/
randomHexDigit: function() {
return randomElement(HEX_DIGITS);
},
/**
* Returns a random string of hex digits with length 'len'.
* @param len the length.
*/
randomHexString: function (len) {
var ret = '';
while (len--) {
ret += this.randomHexDigit();
}
return ret;
},
randomElement: randomElement,
randomAlphanumStr: randomAlphanumStr,
randomInt: randomInt
};
function _randomString(length, characters) {
let result = '';

module.exports = RandomUtil;
for (let i = 0; i < length; ++i) {
result += randomElement(characters);
}

return result;
}
Loading

0 comments on commit 4584d89

Please sign in to comment.