Closed Tunmise-Adegoke closed 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)
Hello, I tried running it on mobile and I got a different error
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?
I think it's from centrifugo because that's the only websocket on the app.
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?
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.
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.
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'
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.
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.
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:
❯ 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
@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?
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.
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?
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.
I tired another method apart from this and it worked. I can connect and subscribe with ease.
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 .
Yay! For web.Thank you
I tried connecting to a remote centrifugo deployment using the code above and got the error below,
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