message: add reconnection if websocket dies
diff: @@ -37,6 +37,8 @@ export interface ICardstackWalletConnectProviderOptions
  rpcWss: IRPCMap;
  }
  +const MIN_RECONNECTION_INTERVAL = 5000;
  +
  class WalletConnectProvider extends ExtendedProviderEngine {
  public bridge = 'https://bridge.walletconnect.org';
  public qrcode = true;
  @@ -55,6 +57,7 @@ class WalletConnectProvider extends ExtendedProviderEngine {
  public websocketProvider!: TypedWebsocketProviderWithConstructor;
  public networkId!: number;
  public infuraId?: string;
  + private lastReconnection = -Infinity;
  constructor(opts: ICardstackWalletConnectProviderOptions) {
  super({
  @@ -81,8 +84,7 @@ class WalletConnectProvider extends ExtendedProviderEngine {
  this.rpcWss = rpcWss;
  this.chainId = chainId;
  this.websocketProvider = websocketProvider;
  - this.websocketProvider.on('close', this.onWebsocketClose.bind(this));
  - this.websocketProvider.on('connect', this.onWebsocketConnect.bind(this));
  + this.bindSocketListeners();
  this.bridge = opts.connector
  ? opts.connector.bridge
  : opts.bridge || 'https://bridge.walletconnect.org';
  @@ -517,6 +519,29 @@ class WalletConnectProvider extends ExtendedProviderEngine {
  };
  }
  + bindSocketListeners() {
  + this.websocketProvider.on('close', this.onWebsocketClose.bind(this));
  + this.websocketProvider.on('connect', this.onWebsocketConnect.bind(this));
  + }
  +
  + async maybeReconnect() {
  + setTimeout(() => {
  + try {
  + console.log('attempting websocket reconnection');
  + if (Date.now() - this.lastReconnection < MIN_RECONNECTION_INTERVAL) {
  + this.emit('websocket-disconnected');
  + return;
  + }
  + this.lastReconnection = Date.now();
  + this.websocketProvider.reset();
  + this.bindSocketListeners();
  + this.websocketProvider.connect();
  + } catch (e) {
  + this.emit('websocket-disconnected');
  + }
  + }, 0);
  + }
  +
  async onWebsocketConnect() {
  console.log('websocket connected', this.websocketProvider.connection.url);
  Sentry.addBreadcrumb({
  @@ -548,6 +573,7 @@ class WalletConnectProvider extends ExtendedProviderEngine {
  ? Sentry.Severity.Info
  : Sentry.Severity.Error,
  });
  + this.maybeReconnect();
  }
  }
  