AS-Devs / signalr_flutter

A flutter plugin for .net SignalR client.
https://pub.dev/packages/signalr_flutter
MIT License
18 stars 29 forks source link

isConnected() not working as expected #30

Open AliEasy opened 3 years ago

AliEasy commented 3 years ago

Hi. Thanks for adding isConnected() feature, but its not working as expected

Before calling connect() I check isConnected() to avoid multi calls but isConnected() always returns true even if signal r is not connected

And I know its not connected because by using hubCallback.call('hub_name', 'hub_method') nothing happens and also Im not getting any call backs from hub

My Code

    Map<String, String> header = {'username': '1'};
    _signalR = SignalR('url', 'hub_name',
        hubMethods: ['hub_method'],
        statusChangeCallback: (status) => _onStatusChange(status),
        hubCallback: (methodName, message) =>
            _onHubCallback({methodName: message}),
        headers: header);

    bool isConnected = await _signalR.isConnected;
    if (!isConnected) {
      bool status = await _signalR.connect();
      print("Signal Connecting : $status");
    }else{
      _signalR.hubCallback.call('hub_name', 'hub_method');
    }
AyonAB commented 3 years ago

Well I tried the example app on both Android & iOS. isConnected seems to be working fine for me.

AliEasy commented 3 years ago

Ok so I will test it again and let you know

AliEasy commented 3 years ago

this may prove that isConnected() not working properly

this is my code:

SignalR signalR = SignalR(
        '<Your server url here>',
        "<Your hub name here>",
        hubMethods: ["hubMethod1", "hubMethod2"]
        statusChangeCallback: (status) => print(status),
        hubCallback: (methodName, message) => print('MethodName = $methodName, Message = $message'));

while(await _signalR.isConnected){
      _signalR.stop();
      print('stop');
    }

and the output is: image

and it Does not stop printing 'stop'