signalr_flutter icon indicating copy to clipboard operation
signalr_flutter copied to clipboard

isConnected() not working as expected

Open AliEasy opened this issue 3 years ago • 3 comments

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');
    }

AliEasy avatar May 26 '21 09:05 AliEasy

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

AyonAB avatar May 30 '21 15:05 AyonAB

Ok so I will test it again and let you know

AliEasy avatar Jun 19 '21 09:06 AliEasy

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'

AliEasy avatar Jun 20 '21 10:06 AliEasy