Creates RandomUtil class for generating random strings.
This commit is contained in:
parent
436fb87fee
commit
13268f9951
|
@ -0,0 +1,37 @@
|
|||
|
||||
/**
|
||||
* Generates random hex number within the range [min, max]
|
||||
* @param max the maximum value for the generated number
|
||||
* @param min the minimum value for the generated number
|
||||
* @returns random hex number
|
||||
*/
|
||||
function rangeRandomHex(min, max)
|
||||
{
|
||||
return Math.floor(Math.random() * (max - min) + min).toString(16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exported interface.
|
||||
*/
|
||||
var RandomUtil = {
|
||||
/**
|
||||
* Generates hex number with length 4
|
||||
*/
|
||||
random4digitsHex: function() {
|
||||
return rangeRandomHex(4096, 65535);
|
||||
},
|
||||
/**
|
||||
* Generates hex number with length 8
|
||||
*/
|
||||
random8digitsHex: function() {
|
||||
return rangeRandomHex(268435456, 4294967295);
|
||||
},
|
||||
/**
|
||||
* Generates hex number with length 12
|
||||
*/
|
||||
random12digitsHex: function() {
|
||||
return rangeRandomHex(17592186044416, 281474976710655);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = RandomUtil;
|
|
@ -32,6 +32,7 @@
|
|||
*/
|
||||
|
||||
var SDP = require('./SDP');
|
||||
var RandomUtil = require('../util/RandomUtil');
|
||||
var RTCBrowserType = require('../RTC/RTCBrowserType');
|
||||
|
||||
/**
|
||||
|
@ -124,38 +125,13 @@ var storeLocalVideoSSRC = function (jingleIq) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates random hex number within the range [min, max]
|
||||
* @param max the maximum value for the generated number
|
||||
* @param min the minimum value for the generated number
|
||||
* @returns random hex number
|
||||
*/
|
||||
function rangeRandomHex(min, max)
|
||||
{
|
||||
return Math.floor(Math.random() * (max - min) + min).toString(16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates hex number with length 4
|
||||
*/
|
||||
var random4digitsHex = rangeRandomHex.bind(null, 4096, 65535);
|
||||
|
||||
/**
|
||||
* Generates hex number with length 8
|
||||
*/
|
||||
var random8digitsHex = rangeRandomHex.bind(null, 268435456, 4294967295);
|
||||
|
||||
/**
|
||||
* Generates hex number with length 12
|
||||
*/
|
||||
var random12digitsHex = rangeRandomHex.bind(null, 17592186044416, 281474976710655);
|
||||
|
||||
/**
|
||||
* Generates new label/mslabel attribute
|
||||
* @returns {string} label/mslabel attribute
|
||||
*/
|
||||
function generateLabel() {
|
||||
return random8digitsHex() + "-" + random4digitsHex() + "-" + random4digitsHex() + "-" + random4digitsHex() + "-" + random12digitsHex();
|
||||
return RandomUtil.random8digitsHex() + "-" + RandomUtil.random4digitsHex() + "-" +
|
||||
RandomUtil.random4digitsHex() + "-" + RandomUtil.random4digitsHex() + "-" + RandomUtil.random12digitsHex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue