diff options
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 34 |
1 files changed, 16 insertions, 18 deletions
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<void> { 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 { |
