From 1afb236c2d6828883e139652dd8c89d8949b8039 Mon Sep 17 00:00:00 2001 From: Maks Jopek Date: Wed, 26 May 2021 18:50:18 +0200 Subject: Version v1.0.2 --- src/index.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 670e861..5845a7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,23 +35,21 @@ export default class Irc { this.poll(); } - poll(): void { + async poll(): Promise { console.log("polling"); - $.ajax({ - url: this.messages.url + "poll", - success: msg => { - this.messages.addMessage(msg); - const update = - document.activeElement === this.input ? "bottom" : "relative"; - - this.helpers.updateScrollbar(update); - this.poll(); - }, - error: () => { - this.poll(); - }, - timeout: 30000, // 30 seconds - }); + + fetch(this.messages.url + "poll") + .then(msg => + msg.json().then(msg => { + this.messages.addMessage(msg); + const update = + document.activeElement === this.input ? "bottom" : "relative"; + + this.helpers.updateScrollbar(update); + this.poll(); + }) + ) + .catch(this.poll); } messageExe(msg: string): boolean { @@ -69,7 +67,7 @@ export default class Irc { if (msg.startsWith("quit") === true) { msgToSend.text = `User ${this.username} has left the chat`; this.messages.sendMessage(msgToSend); - + this.helpers.suicide( "Thank you for using this site, you can now safely close it." ); @@ -79,7 +77,7 @@ export default class Irc { if (this.helpers.isColor(color) === true) { msgToSend.text = `User ${this.username} has changed his color to ${color}`; this.messages.sendMessage(msgToSend); - + this.color = color; } else { this.divError.innerText = "You need to give correct color!"; @@ -92,7 +90,7 @@ export default class Irc { } else { msgToSend.text = `User ${this.username} has changed his nick to ${username}`; this.messages.sendMessage(msgToSend); - + this.username = username; } } else { -- cgit v1.3.1