Reconnect on failure, with backoff; Deduping notifications

This commit is contained in:
Philipp Heckel
2022-02-24 09:52:49 -05:00
parent 3fac1c3432
commit 1536201e9a
6 changed files with 62 additions and 45 deletions

View File

@@ -1,24 +1,15 @@
import {topicUrl, shortTopicUrl, topicUrlWs} from './utils';
export default class Subscription {
id = '';
baseUrl = '';
topic = '';
notifications = [];
lastActive = null;
constructor(baseUrl, topic) {
this.id = topicUrl(baseUrl, topic);
this.baseUrl = baseUrl;
this.topic = topic;
this.notifications = new Map();
}
addNotification(notification) {
if (notification.time === null) {
return this;
}
this.notifications.push(notification);
this.lastActive = notification.time;
this.notifications.set(notification.id, notification);
return this;
}
@@ -27,12 +18,8 @@ export default class Subscription {
return this;
}
url() {
return this.id;
}
wsUrl() {
return topicUrlWs(this.baseUrl, this.topic);
getNotifications() {
return Array.from(this.notifications.values());
}
shortUrl() {