Thanks to visit codestin.com
Credit goes to github.com

Skip to content

innerWebSocket undefined after upgrade #1701

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

Open
RazaGR opened this issue Jan 18, 2025 · 2 comments
Open

innerWebSocket undefined after upgrade #1701

RazaGR opened this issue Jan 18, 2025 · 2 comments

Comments

@RazaGR
Copy link

RazaGR commented Jan 18, 2025

I want to upgrade the package from 2.4.0 to 3.0.1 , any idea how can I access readyState anymore?
earlier I was doing

 _channel?.innerWebSocket?.readyState
@mosuem mosuem transferred this issue from dart-archive/web_socket_channel Jan 22, 2025
@brianquinlan
Copy link
Collaborator

Does WebSocketChannel.ready provide the information that you need?

@brianquinlan brianquinlan added the needs-info Additional information needed from the issue author label May 1, 2025
@RazaGR
Copy link
Author

RazaGR commented May 2, 2025

Thanks for the suggestion! Unfortunately, not quite — WebSocketChannel.ready is helpful during the connection phase, but in my case, I need to check the state of an already established connection before calling _channel!.ready. Previously, I used _channel?.innerWebSocket?.readyState to determine whether the socket was still connected or not, especially in situations where the connection might have been dropped silently.

Is there an equivalent way to get the current readyState in 3.0.1? Here's a quick example of how I was using it:

class WebSocketRepository {
  dynamic _channel;

  Future<bool> connect(Uri url) async {
   // confirm if its already connected, so we dont call connect again
    if (_channel?.innerWebSocket?.readyState == 1) {
      debugPrint('Already connected!');
      return true;
    }

    // make connection 
    _channel = defaultTargetPlatform == TargetPlatform.iOS ||
            defaultTargetPlatform == TargetPlatform.android
        ? IOWebSocketChannel.connect(url)
        : WebSocketChannel.connect(url);
    try {
      await _channel!.ready;
    } catch (e) {
      debugPrint('Error Exception repo $e');
    }

    // confirming connection again
    if (_channel?.innerWebSocket?.readyState == 1) {
      return true;
    } else {
      return false;
    }
  }
...
}

@github-actions github-actions bot removed the needs-info Additional information needed from the issue author label May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants