[mirotalk] - improve room id generator

This commit is contained in:
Miroslav Pejic
2021-03-17 21:17:26 +01:00
parent caf1762ea2
commit 0ecfed4073
+17 -1
View File
@@ -192,13 +192,29 @@ function getRoomId() {
let roomId = location.pathname.substring(1);
// if not specified room id, create one random
if (roomId == "") {
roomId = Math.random().toString(36).substr(2, 10);
roomId = makeId(12);
const newurl = signalingServer + "/" + roomId;
window.history.pushState({ url: newurl }, roomId, newurl);
}
return roomId;
}
/**
* Generate random Id
* @param {*} length
* @returns random id
*/
function makeId(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
/**
* Check if there is peer connections
* @return true, false otherwise