Do not fetch old messages on old connecting to avoid douple rendering
This commit is contained in:
parent
1536201e9a
commit
202c4ac4b3
2 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
import {shortTopicUrl, topicUrlWs} from "./utils";
|
import {shortTopicUrl, topicUrlWs, topicUrlWsWithSince} from "./utils";
|
||||||
|
|
||||||
const retryBackoffSeconds = [5, 10, 15, 20, 30, 45, 60, 120];
|
const retryBackoffSeconds = [5, 10, 15, 20, 30, 45, 60, 120];
|
||||||
|
|
||||||
|
@ -16,8 +16,11 @@ class Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
const since = (this.since === 0) ? "all" : this.since.toString();
|
// Don't fetch old messages; we do that as a poll() when adding a subscription;
|
||||||
const wsUrl = topicUrlWs(this.baseUrl, this.topic, since);
|
// we don't want to re-trigger the main view re-render potentially hundreds of times.
|
||||||
|
const wsUrl = (this.since === 0)
|
||||||
|
? topicUrlWs(this.baseUrl, this.topic)
|
||||||
|
: topicUrlWsWithSince(this.baseUrl, this.topic, this.since.toString());
|
||||||
console.log(`[Connection, ${this.shortUrl}] Opening connection to ${wsUrl}`);
|
console.log(`[Connection, ${this.shortUrl}] Opening connection to ${wsUrl}`);
|
||||||
this.ws = new WebSocket(wsUrl);
|
this.ws = new WebSocket(wsUrl);
|
||||||
this.ws.onopen = (event) => {
|
this.ws.onopen = (event) => {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
export const topicUrl = (baseUrl, topic) => `${baseUrl}/${topic}`;
|
export const topicUrl = (baseUrl, topic) => `${baseUrl}/${topic}`;
|
||||||
export const topicUrlWs = (baseUrl, topic, since) => `${topicUrl(baseUrl, topic)}/ws?since=${since}`
|
export const topicUrlWs = (baseUrl, topic) => `${topicUrl(baseUrl, topic)}/ws`
|
||||||
.replaceAll("https://", "wss://")
|
.replaceAll("https://", "wss://")
|
||||||
.replaceAll("http://", "ws://");
|
.replaceAll("http://", "ws://");
|
||||||
|
export const topicUrlWsWithSince = (baseUrl, topic, since) => `${topicUrlWs(baseUrl, topic)}?since=${since}`;
|
||||||
export const topicUrlJson = (baseUrl, topic) => `${topicUrl(baseUrl, topic)}/json`;
|
export const topicUrlJson = (baseUrl, topic) => `${topicUrl(baseUrl, topic)}/json`;
|
||||||
export const topicUrlJsonPoll = (baseUrl, topic) => `${topicUrlJson(baseUrl, topic)}?poll=1`;
|
export const topicUrlJsonPoll = (baseUrl, topic) => `${topicUrlJson(baseUrl, topic)}?poll=1`;
|
||||||
export const shortUrl = (url) => url.replaceAll(/https?:\/\//g, "");
|
export const shortUrl = (url) => url.replaceAll(/https?:\/\//g, "");
|
||||||
|
|
Loading…
Reference in a new issue