Limit reconnect retries to 5

This commit is contained in:
Tommy Chow 2023-11-28 04:13:53 -05:00
parent 12d00b16cc
commit c937c4a6fc

View file

@ -57,6 +57,8 @@ abstract class ChatStoreBase with Store {
StreamSubscription? _sevenTVChannelListener;
static const _maxRetries = 5;
// The retry counter for exponential backoff.
var _retries = 0;
@ -451,6 +453,15 @@ abstract class ChatStoreBase with Store {
onDone: () async {
if (_channel == null) return;
if (_retries >= _maxRetries) {
messageBuffer.add(
IRCMessage.createNotice(
message: 'Disconnected from chat',
),
);
return;
}
if (_backoffTime > 0) {
// Add notice that chat was disconnected and then wait the backoff time before reconnecting.
final notice =