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:
18
index.js
18
index.js
@ -49,7 +49,7 @@ var service = {
|
|||||||
host: "127.0.0.1", // when omitted, defaults to the local IP
|
host: "127.0.0.1", // when omitted, defaults to the local IP
|
||||||
port: PORT,
|
port: PORT,
|
||||||
memberCount: 1,
|
memberCount: 1,
|
||||||
UUID: ""
|
UUID: "",
|
||||||
// any additional information is allowed and will be propagated
|
// 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);
|
console.log("A new session was announced", serviceInfo.service);
|
||||||
// List currently known services
|
// List currently known services
|
||||||
//knownSessions.push(serviceInfo.service);
|
//knownSessions.push(serviceInfo.service);
|
||||||
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service
|
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service;
|
||||||
});
|
});
|
||||||
|
|
||||||
diont.on("serviceRenounced", function (serviceInfo) {
|
diont.on("serviceRenounced", function (serviceInfo) {
|
||||||
//console.log("A session was renounced", serviceInfo.service);
|
//console.log("A session was renounced", serviceInfo.service);
|
||||||
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service
|
knownSessionsByUUID[serviceInfo.service.UUID] = serviceInfo.service;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Preload all pages
|
// Preload all pages
|
||||||
@ -346,16 +346,16 @@ function init() {
|
|||||||
while (sessinUids.includes(uidSes)) {
|
while (sessinUids.includes(uidSes)) {
|
||||||
uidSes = nanoid();
|
uidSes = nanoid();
|
||||||
rounds++;
|
rounds++;
|
||||||
if(rounds >= 10000){
|
if (rounds >= 10000) {
|
||||||
// This takes a lot of rounds, there are two possible reasons to this:
|
// This takes a lot of rounds, there are two possible reasons to this:
|
||||||
// A lot of sessions or a broken nanoid() random generation
|
// 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.
|
// 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;
|
sessionState = 4;
|
||||||
return("")
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,13 @@
|
|||||||
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
|
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
|
||||||
Start session search
|
Start session search
|
||||||
</button>
|
</button>
|
||||||
|
<table id="sessionListTa">
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Host</th>
|
||||||
|
<th>Amount of members</th>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<script>
|
<script>
|
||||||
function createNewSession() {
|
function createNewSession() {
|
||||||
val = document.getElementById("sessionName").value
|
val = document.getElementById("sessionName").value
|
||||||
@ -26,10 +33,30 @@
|
|||||||
alert("Your Sessionname may not contain a |");
|
alert("Your Sessionname may not contain a |");
|
||||||
}
|
}
|
||||||
console.log(val)
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -221,6 +221,13 @@
|
|||||||
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
|
<button onclick='ipcRenderer.sendSync("synchronous-message", "SESSION:startSearch");'>
|
||||||
Start session search
|
Start session search
|
||||||
</button>
|
</button>
|
||||||
|
<table id="sessionListTa">
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Host</th>
|
||||||
|
<th>Amount of members</th>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<script>
|
<script>
|
||||||
function createNewSession() {
|
function createNewSession() {
|
||||||
val = document.getElementById("sessionName").value
|
val = document.getElementById("sessionName").value
|
||||||
@ -229,10 +236,30 @@
|
|||||||
alert("Your Sessionname may not contain a |");
|
alert("Your Sessionname may not contain a |");
|
||||||
}
|
}
|
||||||
console.log(val)
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user