Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔌 Silent WebSocket Disconnects #8

Closed
ghunkins opened this issue Dec 6, 2021 · 2 comments
Closed

🔌 Silent WebSocket Disconnects #8

ghunkins opened this issue Dec 6, 2021 · 2 comments

Comments

@ghunkins
Copy link

ghunkins commented Dec 6, 2021

Issue

SocketTransport handles disconnects (onError or onDone events) silently by marking itself as not connected. When these disconnects occur, a WalletConnectSession appears to be connected but cannot send or receive messages.

Impact

In release and profile mode, when a user puts the app into the background (i.e. to sign a message in their wallet app), the sockets get closed. On return, the session can't send or receive messages despite it looking connected.

Fix

Re-open the socket when onError and onDone events are fired.

I am opening a PR on this and will link it here.

@bobwith2bees
Copy link

bobwith2bees commented Feb 23, 2022

This may viable workaround:

  // add to ScreenState  'with WidgetsBindingObserver '
  // https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html

  @override
  void initState() {
    // Register observer so we can see app lifecycle changes.
    WidgetsBinding.instance!.addObserver(this);
    super.initState();
  }

  /// The wallet connect client, sometimes loses the webSocket connection when the app is suspended
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    DateFormat dateFormat = DateFormat("HH:mm:ss");
    String dateString = dateFormat.format(DateTime.now());

    logger.d("$dateString AppLifecycleState: ${state.toString()}.");

    if (state == AppLifecycleState.resumed) {
      if (mounted) {
        if (walletConnect.connected && walletConnect.transport.connected == false)) {
          logger.e('$dateString  Wallet connected, but transport is down.  Attempt to recover.');
          walletConnect.transport.open();
        }
      }
    }
  }

  @override
  void dispose() {
    super.dispose();
    // Remove observer for app lifecycle changes.
    WidgetsBinding.instance!.removeObserver(this);
  }

@RootSoft
Copy link
Owner

RootSoft commented Mar 8, 2022

The reconnection logic is now improved in v0.0.8.
We will also introduce a Flutter widget to keep the connection alive, based on @bobwith2bees code.

Thanks @bobwith2bees and @ghunkins

@RootSoft RootSoft closed this as completed Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants