summaryrefslogtreecommitdiffstats
path: root/src/index.ts
diff options
context:
space:
mode:
authorMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-05-26 18:50:18 +0200
committerMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-05-26 18:50:18 +0200
commit1afb236c2d6828883e139652dd8c89d8949b8039 (patch)
tree905386f1ee4210937682d62d7f75bdc771184c80 /src/index.ts
parentaa13f322e2d59fdc3c50371572c0cad443b798ec (diff)
downloadIRC-1afb236c2d6828883e139652dd8c89d8949b8039.tar.gz
IRC-1afb236c2d6828883e139652dd8c89d8949b8039.tar.zst
IRC-1afb236c2d6828883e139652dd8c89d8949b8039.zip
Version v1.0.2
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts34
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 {