Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket close notify #123

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## 8.2.1

* Fix OAuth issue on web
* Make improvements in helper classes
* Fix: notify callback when websocket closes [#604](https://github.com/appwrite/sdk-generator/pull/604)

## 8.2.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square)](https://pub.dartlang.org/packages/appwrite)
![License](https://img.shields.io/github/license/appwrite/sdk-for-flutter.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.2.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.2.1-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down
18 changes: 10 additions & 8 deletions lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ class ClientIO extends ClientBase with ClientMixin {
Future init() async {
if(_initProgress) return;
_initProgress = true;
// if web skip cookie implementation and origin header as those are automatically handled by browsers
final Directory cookieDir = await _getCookiePath();
_cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
_interceptors.add(CookieManager(_cookieJar));
PackageInfo packageInfo = await PackageInfo.fromPlatform();
addHeader('Origin',
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');

//creating custom user agent
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
var device = '';
try {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
addHeader('Origin',
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');

//creating custom user agent
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
if (Platform.isAndroid) {
final andinfo = await deviceInfoPlugin.androidInfo;
device =
Expand All @@ -174,12 +174,14 @@ class ClientIO extends ClientBase with ClientMixin {
final macinfo = await deviceInfoPlugin.macOsInfo;
device = '(Macintosh; ${macinfo.model})';
}
addHeader(
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
} catch (e) {
debugPrint('Error getting device info: $e');
device = Platform.operatingSystem;
addHeader(
'user-agent', '$device');
}
addHeader(
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');

_initialized = true;
_initProgress = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cookie_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class CookieManager extends Interceptor {
}
return request;
}).catchError((e, stackTrace) {
// throw AppwriteException(e.message);
return request;
});
return request;
}

@override
FutureOr<http.Response> onResponse(http.Response response) {
_saveCookies(response).then((_) => response).catchError((e, stackTrace) {
// throw AppwriteException(e.message);
return response;
});
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Locale implements Model {
final String continentCode;
/// Continent name. This field support localization.
final String continent;
/// True if country is part of the Europian Union.
/// True if country is part of the European Union.
final bool eu;
/// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format
final String currency;
Expand Down
18 changes: 18 additions & 0 deletions lib/src/realtime_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ mixin RealtimeMixin {
}
break;
}
}, onDone: () {
for (var list in _channels.values) {
for (var stream in list) {
stream.close();
}
}
_channels.clear();
_closeConnection();
}, onError: (err, stack) {
for (var list in _channels.values) {
for (var stream in list) {
stream.sink.addError(err, stack);
}
}
if (_websok?.closeCode != null && _websok?.closeCode != 1008) {
debugPrint("Reconnecting in one second.");
Future.delayed(Duration(seconds: 1), _createSocket);
}
});
} catch (e) {
if (e is AppwriteException) {
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ dependencies:
flutter_web_auth_2: ^2.0.2
http: ^0.13.5
package_info_plus: ^3.0.2
path_provider: ^2.0.11
path_provider: ^2.0.12
web_socket_channel: ^2.2.0
universal_html: ^2.0.8

dev_dependencies:
path_provider_platform_interface: ^2.0.5
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter