centrifugal / centrifuge-dart

Dart (Flutter) client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket
https://pub.dartlang.org/packages/centrifuge
MIT License
102 stars 29 forks source link

getting transport error on connect. #71

Closed Tunmise-Adegoke closed 1 year ago

Tunmise-Adegoke commented 1 year ago

centrihhj

I tried connecting to a remote centrifugo deployment using the code above and got the error below,

centrifugo

I want to add that this is the version of the dart package I'm using centrifuge: ^0.9.2 and the version of the remote deployment is 4.1.2

FZambia commented 1 year ago

Hello @Tunmise-Adegoke

How you are running it? Is it for web? (this sdk does not work for web at the moment, see open issue https://github.com/centrifugal/centrifuge-dart/issues/34)

Tunmise-Adegoke commented 1 year ago

Hello, I tried running it on mobile and I got a different error centri 2

FZambia commented 1 year ago

I see in the mobile logs that Centrifuge client successfully connected to the server and got unauthorized reason for subscription. Is that SocketException you observe raises from inside centrifuge-dart library? Or maybe its unrelated?

Tunmise-Adegoke commented 1 year ago

I think it's from centrifugo because that's the only websocket on the app.

FZambia commented 1 year ago

Can you check this? It may be from any other network activity I suppose - nothing in the exception says it's coming from the WebSocket. What's happening with the WebSocket connection after this error occurs btw?

Tunmise-Adegoke commented 1 year ago

The websockets disconnects. I'm making some other network calls though but I don't think it should affect it. But the websocket disconnects after a minute.

FZambia commented 1 year ago

If WebSocket disconnects a minute after being established this may be your proxy configuration which does not allow long-lived connections. So it may simply be a separate thing.

You may be right that the error comes from Centrifuge-dart. Or may be not. Since you have the reproducer you have all the power to check it. Or submit minimal reproducing steps without your app specifics so I could also take a closer look.

Tunmise-Adegoke commented 1 year ago

This is my full code tiny info I might add when connecting to the server through the centrifugo JS SDK it works well. websocketurl = 'ws://realtime.mize.app/connection/websocket?cf_protocol_version=v2' c1 c2 c3 c4

FZambia commented 1 year ago

OMG, do you think I can run your screenshots?

Post the reproducing code (minimal, without your app specifics) as a repo on Github, give me instructions how to run it.

Tunmise-Adegoke commented 1 year ago

Hello, This is a link to the repo I created https://github.com/Tunmise-Adegoke/centrifugo_project copy the code and clone it on your editor. Make sure you have dart and flutter installed to run it then use an android emulator to run the app.

FZambia commented 1 year ago

Hello @Tunmise-Adegoke

Thanks for posting example, I managed to run it for both MacOS desktop app and in Android emulator. In both cases it works without any issues. And WebSocket connection not closed at all. Here is an output when running in Android emulator:

Screenshot 2023-01-18 at 19 00 34
❯ flutter --version
Flutter 3.3.10 • channel stable • ssh://git@github.com/flutter/flutter.git
Framework • revision 135454af32 (5 weeks ago) • 2022-12-15 07:36:55 -0800
Engine • revision 3316dd8728
Tools • Dart 2.18.6 • DevTools 2.15.0
FZambia commented 1 year ago

@Tunmise-Adegoke any updates? do you see a different output when running on your machine? Have you tried to update flutter to the latest version?

Tunmise-Adegoke commented 1 year ago

Hello@FZambia, I gave you an unlimited token which works perfectly on my own end too. I'm have been trying to generate a token from my api to test it. I have been getting errors so that's why I haven't replied since.

Tunmise-Adegoke commented 1 year ago

Hello @FZambia, as seen in your screenshot, your event was unsubscribed for unauthorised reasons. I'm facing the same issue. Please do you know the reason?

FZambia commented 1 year ago

Yes, the reason is that the code uses dummy getToken for Subscription: https://github.com/Tunmise-Adegoke/centrifugo_project/blob/f39da4727641f48e0b5b0d87b60ee6b0e8cffffb/lib/client/client.dart#L55

Instead of:

    final subscription = client.newSubscription(
      channel,
      centrifuge.SubscriptionConfig(
        getToken: (centrifuge.SubscriptionTokenEvent event) {
          return Future.value('');
        },
      ),
    );

You should use whether:

    final subscription = client.newSubscription(
      channel,
      centrifuge.SubscriptionConfig(),
    );

Or load subscription token properly (now returning Future.value(''); in Subscription getToken tells SDK that client does not have permissions to subscribe on channel - this is described here).

I can't say exactly which way you need – depends on server permission configuration.

Tunmise-Adegoke commented 1 year ago

I tired another method apart from this and it worked. I can connect and subscribe with ease.

FZambia commented 1 year ago

Closing – as far as I understand all is good here. BTW, centrifuge-dart SDK will also support web in the next release - was just added in #73 .

Tunmise-Adegoke commented 1 year ago

Yay! For web.Thank you