Small js fixes
This commit is contained in:
@ -76,8 +76,6 @@ export class App {
|
||||
console.warn(`Invalid url hash #${hash}`);
|
||||
return defaultCase();
|
||||
}
|
||||
|
||||
//this.setHash(hash);
|
||||
}
|
||||
|
||||
async login(accountName, domainName, password) {
|
||||
@ -161,7 +159,7 @@ export class App {
|
||||
<button type="submit">Login</button>
|
||||
</form>`;
|
||||
|
||||
win.getElementsByTagName("form")[0].addEventListener("submit", async (event) => {
|
||||
win.getElementsByTagName("form")[0].addEventListener("submit", async event => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
for (const e of form) {
|
||||
@ -169,28 +167,24 @@ export class App {
|
||||
e.removeAttribute("invalid");
|
||||
}
|
||||
|
||||
for (const d of form.getElementsByTagName("div")) {
|
||||
form.removeChild(d);
|
||||
}
|
||||
|
||||
function formError(msg) {
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("error");
|
||||
div.innerText = msg;
|
||||
form.appendChild(div);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.login(form.account.value, form.domain.value, form.password.value);
|
||||
try {
|
||||
await this.login(form.account.value, form.domain.value, form.password.value);
|
||||
} finally {
|
||||
for (const d of form.getElementsByTagName("div")) form.removeChild(d);
|
||||
for (const e of form) e.disabled = false;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.toString() === "Error: unable to authenticate") {
|
||||
document.getElementsByName("account")[0].setAttribute("invalid", "invalid");
|
||||
} else {
|
||||
document.getElementsByName("domain")[0].setAttribute("invalid", "invalid");
|
||||
}
|
||||
formError(error.toString());
|
||||
} finally {
|
||||
for (const e of form) e.disabled = false;
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("error");
|
||||
div.innerText = error.toString();
|
||||
form.appendChild(div);
|
||||
}
|
||||
});
|
||||
|
||||
@ -217,13 +211,14 @@ export class App {
|
||||
</div>`;
|
||||
|
||||
const input = document.getElementsByName("message")[0];
|
||||
input.addEventListener("keyup", (event) => {
|
||||
input.addEventListener("keyup", async event => {
|
||||
if (event.key === "Enter" && input.value.length > 0) {
|
||||
this.session.sendEvent("60nc0XXDIYUh6QzX4p0rMpCdzDmxghZLZk8dLuQh628", {
|
||||
message: input.value,
|
||||
});
|
||||
this.addMessage(input.value);
|
||||
const val = input.value;
|
||||
input.value = "";
|
||||
await this.session.sendEvent("60nc0XXDIYUh6QzX4p0rMpCdzDmxghZLZk8dLuQh628", {
|
||||
message: val,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -25,7 +25,7 @@ export class Domain {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 2000);
|
||||
|
||||
let response = await fetch(`https://${domainName}/.well-known/usimp.json`, {
|
||||
const response = await fetch(`https://${domainName}/.well-known/usimp.json`, {
|
||||
redirect: "manual",
|
||||
signal: controller.signal,
|
||||
});
|
||||
@ -166,7 +166,7 @@ export class Session {
|
||||
}
|
||||
|
||||
const startTime = new Date();
|
||||
let response = await fetch(`${this.httpBaseUrl}/${endpoint}`, {
|
||||
const response = await fetch(`${this.httpBaseUrl}/${endpoint}`, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(data),
|
||||
@ -175,7 +175,7 @@ export class Session {
|
||||
const endTime = new Date();
|
||||
clearTimeout(timer);
|
||||
|
||||
let responseData = await response.json();
|
||||
const responseData = await response.json();
|
||||
responseData.duration = endTime - startTime;
|
||||
return responseData;
|
||||
}
|
||||
@ -183,16 +183,19 @@ export class Session {
|
||||
|
||||
async ping() {
|
||||
let result = {"http": null, "ws": null};
|
||||
const res = await this.send("ping", {}, undefined, true);
|
||||
result.http = res.duration;
|
||||
const resHttp = await this.send("ping", {}, undefined, true);
|
||||
result.http = resHttp.duration;
|
||||
|
||||
if (this.wsConnection) {
|
||||
await this.wsConnection.ping();
|
||||
const resWs = await this.send("ping", {});
|
||||
result.ws = resWs.duration;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async authenticate(accountName, password) {
|
||||
let response = await this.send("authenticate", {
|
||||
const response = await this.send("authenticate", {
|
||||
type: "password",
|
||||
name: accountName,
|
||||
password: password,
|
||||
|
Reference in New Issue
Block a user