fix: do not reconnect server if fail to many times (#1735)

This commit is contained in:
Himself65 2023-03-28 22:50:01 -05:00 committed by GitHub
parent 998587b3b8
commit eb33289f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
/* eslint-env browser */
// import * as Y from 'yjs'; // eslint-disable-line
import { toast } from '@affine/component';
import * as bc from 'lib0/broadcastchannel';
import * as decoding from 'lib0/decoding';
import * as encoding from 'lib0/encoding';
@ -127,6 +128,11 @@ const readMessage = (provider, buf, emitSynced) => {
* @param {WebsocketProvider} provider
*/
const setupWS = provider => {
// failed too many times to reconnect
if (provider.wsUnsuccessfulReconnects >= 5) {
toast('Unable to connect to server. Please try again later.');
provider.shouldConnect = false;
}
if (provider.shouldConnect && provider.ws === null) {
const websocket = new provider._WS(provider.url);
websocket.binaryType = 'arraybuffer';