Merge pull request #7 from MDMCK10/master

Bug fixes + small change
This commit is contained in:
DarkOK 2023-05-01 14:57:02 +01:00 committed by GitHub
commit af48aa7e19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

2
dist/index.html vendored
View file

@ -54,7 +54,7 @@
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link active" aria-current="page"><i class="fa-solid fa-house"></i> Home</a>
<a id="homeBtn" href="#" class="nav-link active" aria-current="page"><i class="fa-solid fa-house"></i> Home</a>
</li>
<li class="nav-item">
<a href="https://computernewb.com/collab-vm/faq/" class="nav-link"><i class="fa-solid fa-circle-question"></i> FAQ</a>

View file

@ -14,6 +14,7 @@ var connected = false;
const vms = [];
const users = [];
const buttons = {
home: window.document.getElementById("homeBtn"),
takeTurn: window.document.getElementById("takeTurnBtn"),
changeUsername: window.document.getElementById("changeUsernameBtn"),
voteReset: window.document.getElementById("voteResetButton"),
@ -83,7 +84,8 @@ class CollabVMClient {
rej(e);
}
this.socket.addEventListener('message', (e) => this.#onMessage(e));
this.socket.addEventListener('open', () => res(), {once: true});
this.socket.addEventListener('open', () => res(true), {once: true});
this.socket.addEventListener('close', (e) => { if(!e.wasClean) res(false); }, {once: true});
})
}
@ -602,7 +604,8 @@ class CollabVMClient {
function multicollab(url) {
return new Promise(async (res, rej) => {
var vm = new CollabVMClient(url, false);
await vm.connect();
var connected = await vm.connect();
if(!connected) return res(false);
var list = await vm.list();
vm.disconnect();
list.forEach((curr) => {
@ -714,6 +717,14 @@ function addUserDropdownItem(ul, text, func) {
li.appendChild(a);
ul.appendChild(li);
}
function returnToVMList() {
if(!connected) return;
connected = false;
vm.disconnect();
vmview.style.display = "none";
vmlist.style.display = "block";
}
async function openVM(url, node) {
if (connected) return;
connected = true;
@ -768,6 +779,7 @@ function cleanup() {
display.height = 0;
display.width = 0;
}
buttons.home.addEventListener('click', async () => returnToVMList());
buttons.screenshot.addEventListener('click', async () => {
var blob = await screenshotVM();
var url = URL.createObjectURL(blob);