Skip to content

Commit

Permalink
Better manage subscriptionCounters (mastodon#14608)
Browse files Browse the repository at this point in the history
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
mastodon#14579
to recover subscriptions after a reconnect.
  • Loading branch information
zunda authored and thenameisnigel-old committed Sep 6, 2020
1 parent 284d164 commit 2784949
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions app/javascript/mastodon/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ const sharedCallbacks = {
},

disconnected () {
subscriptions.forEach(({ onDisconnect }) => onDisconnect());
subscriptions.forEach(subscription => unsubscribe(subscription));
},

reconnected () {
subscriptions.forEach(subscription => subscribe(subscription));
},
};

Expand Down Expand Up @@ -252,15 +251,8 @@ const createConnection = (streamingAPIBaseURL, accessToken, channelName, { conne

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 => {
Expand Down

0 comments on commit 2784949

Please sign in to comment.