🐛 Fix connection issue
This commit is contained in:
parent
b4d1d62e9b
commit
8e0e2dacfe
@ -33,12 +33,10 @@ class ChatProvider extends ChangeNotifier {
|
||||
|
||||
WebSocketChannel? _channel;
|
||||
|
||||
Future<WebSocketChannel?> connect(AuthProvider auth) async {
|
||||
Future<WebSocketChannel?> connect(AuthProvider auth, {noRetry = false}) async {
|
||||
if (auth.client == null) await auth.loadClient();
|
||||
if (!await auth.isAuthorized()) return null;
|
||||
|
||||
await auth.client!.refreshToken(auth.client!.currentRefreshToken!);
|
||||
|
||||
var ori = getRequestUri('messaging', '/api/ws');
|
||||
var uri = Uri(
|
||||
scheme: ori.scheme.replaceFirst('http', 'ws'),
|
||||
@ -50,8 +48,15 @@ class ChatProvider extends ChangeNotifier {
|
||||
|
||||
isOpened = true;
|
||||
|
||||
try {
|
||||
_channel = WebSocketChannel.connect(uri);
|
||||
await _channel!.ready;
|
||||
} catch (e) {
|
||||
if (!noRetry) {
|
||||
await auth.client!.refreshToken(auth.client!.currentRefreshToken!);
|
||||
connect(auth, noRetry: true);
|
||||
}
|
||||
}
|
||||
|
||||
_channel!.stream.listen(
|
||||
(event) {
|
||||
|
@ -70,6 +70,7 @@ class NotifyProvider extends ChangeNotifier {
|
||||
AuthProvider auth, {
|
||||
Keypair? Function(String id)? onKexRequest,
|
||||
Function(Keypair kp)? onKexProvide,
|
||||
bool noRetry = false,
|
||||
}) async {
|
||||
if (auth.client == null) await auth.loadClient();
|
||||
if (!await auth.isAuthorized()) return null;
|
||||
@ -87,8 +88,15 @@ class NotifyProvider extends ChangeNotifier {
|
||||
|
||||
isOpened = true;
|
||||
|
||||
try {
|
||||
_channel = WebSocketChannel.connect(uri);
|
||||
await _channel!.ready;
|
||||
} catch (e) {
|
||||
if (!noRetry) {
|
||||
await auth.client!.refreshToken(auth.client!.currentRefreshToken!);
|
||||
connect(auth, noRetry: true);
|
||||
}
|
||||
}
|
||||
|
||||
_channel!.stream.listen(
|
||||
(event) {
|
||||
|
Loading…
Reference in New Issue
Block a user