1
0
mirror of https://github.com/TheGreyDiamond/Enlight.git synced 2025-07-18 04:33:50 +02:00

Added list of sessions in GUI as demo

This commit is contained in:
TheGreyDiamond
2020-12-28 18:50:54 +01:00
parent e1b52adb5a
commit cd72c74a68
3 changed files with 67 additions and 13 deletions

View File

@ -49,7 +49,7 @@ var service = {
host: "127.0.0.1", // when omitted, defaults to the local IP
port: PORT,
memberCount: 1,
UUID: ""
UUID: "",
// any additional information is allowed and will be propagated
};
@ -76,12 +76,12 @@ diont.on("serviceAnnounced", function (serviceInfo) {
console.log("A new session was announced", serviceInfo.service);
// List currently known services
//knownSessions.push(serviceInfo.service);
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service;
});
diont.on("serviceRenounced", function (serviceInfo) {
//console.log("A session was renounced", serviceInfo.service);
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service;
});
// Preload all pages
@ -346,16 +346,16 @@ function init() {
while (sessinUids.includes(uidSes)) {
uidSes = nanoid();
rounds++;
if(rounds >= 10000){
// This takes a lot of rounds, there are two possible reasons to this:
if (rounds >= 10000) {
// This takes a lot of rounds, there are two possible reasons to this:
// A lot of sessions or a broken nanoid() random generation
console.warn("It takes very long to find a unique session UUID")
console.warn("It takes very long to find a unique session UUID");
}
if(rounds >= 40000){
if (rounds >= 40000) {
// Okay, no. We shall give up now. Something is very, very wrong here.
console.error("Took to long to find a session UUID")
console.error("Took to long to find a session UUID");
sessionState = 4;
return("")
return "";
}
}

View File

@ -18,6 +18,13 @@
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
Start session search
</button>
<table id="sessionListTa">
<tr>
<th>Name</th>
<th>Host</th>
<th>Amount of members</th>
</tr>
</table>
<script>
function createNewSession() {
val = document.getElementById("sessionName").value
@ -26,10 +33,30 @@
alert("Your Sessionname may not contain a |");
}
console.log(val)
ipcRenderer.sendSync("synchronous-message", "SESSION:createNew| " + val);
ipcRenderer.sendSync("synchronous-message", "SESSION:createNew|" + val);
}
setInterval(function(){console.log(ipcRenderer.sendSync("synchronous-message", "SESSION:getAll" ));}, 5000)
setInterval(function(){
allSess = ipcRenderer.sendSync("synchronous-message", "SESSION:getAll" )
elmList = document.getElementById("sessionListTa")
elmList.innerHTML = "<tr><th>Name</th><th>Host</th><th>Amount of members</th></tr>"
SesKeys = Object.keys(allSess)
var i = 0
insBlock = ""
while(i < SesKeys.length){
console.log(i, SesKeys[i], allSess[SesKeys[i]])
insBlock = "<tr>"
insBlock += "<td>" + allSess[SesKeys[i]].name + "</td>"
insBlock += "<td>" + allSess[SesKeys[i]].host + "</td>"
insBlock += "<td>" + allSess[SesKeys[i]].memberCount + "</td>"
insBlock += "</tr>"
elmList.innerHTML = elmList.innerHTML + insBlock
i++;
}
console.log(allSess);
}, 5000)
</script>
</body>
</html>

View File

@ -221,6 +221,13 @@
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
Start session search
</button>
<table id="sessionListTa">
<tr>
<th>Name</th>
<th>Host</th>
<th>Amount of members</th>
</tr>
</table>
<script>
function createNewSession() {
val = document.getElementById("sessionName").value
@ -229,10 +236,30 @@
alert("Your Sessionname may not contain a |");
}
console.log(val)
ipcRenderer.sendSync("synchronous-message", "SESSION:createNew| " + val);
ipcRenderer.sendSync("synchronous-message", "SESSION:createNew|" + val);
}
setInterval(function(){console.log(ipcRenderer.sendSync("synchronous-message", "SESSION:getAll" ));}, 5000)
setInterval(function(){
allSess = ipcRenderer.sendSync("synchronous-message", "SESSION:getAll" )
elmList = document.getElementById("sessionListTa")
elmList.innerHTML = "<tr><th>Name</th><th>Host</th><th>Amount of members</th></tr>"
SesKeys = Object.keys(allSess)
var i = 0
insBlock = ""
while(i < SesKeys.length){
console.log(i, SesKeys[i], allSess[SesKeys[i]])
insBlock = "<tr>"
insBlock += "<td>" + allSess[SesKeys[i]].name + "</td>"
insBlock += "<td>" + allSess[SesKeys[i]].host + "</td>"
insBlock += "<td>" + allSess[SesKeys[i]].memberCount + "</td>"
insBlock += "</tr>"
elmList.innerHTML = elmList.innerHTML + insBlock
i++;
}
console.log(allSess);
}, 5000)
</script>
</body>
</html>