Before this change:
- unsubscribe() was not called for a disconnection
- It seems that WebSocketClient calls connected() and reconnected().
subscriptionCounters were incremented twice for a single reconnection,
first from connected() and second from reconnected()
This might be a an additional change to
https://github.com/tootsuite/mastodon/pull/14579
to recover subscriptions after a reconnect.
},
disconnected () {
- subscriptions.forEach(({ onDisconnect }) => onDisconnect());
+ subscriptions.forEach(subscription => unsubscribe(subscription));
},
reconnected () {
- subscriptions.forEach(subscription => subscribe(subscription));
},
};
const es = new EventSource(`${streamingAPIBaseURL}/api/v1/streaming/${channelName}?${params.join('&')}`);
- let firstConnect = true;
-
es.onopen = () => {
- if (firstConnect) {
- firstConnect = false;
- connected();
- } else {
- reconnected();
- }
+ connected();
};
KNOWN_EVENT_TYPES.forEach(type => {