diff --git a/.fvm/fvm_config.json b/.fvm/fvm_config.json index b206278..26eda9b 100644 --- a/.fvm/fvm_config.json +++ b/.fvm/fvm_config.json @@ -1,4 +1,4 @@ { - "flutterSdkVersion": "3.3.1", + "flutterSdkVersion": "3.3.5", "flavors": {} } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a6c85..12c6edf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.18 + +* Updated lime +* Added onConnectionDone Listener + ## 0.0.17 * Updated lime diff --git a/lib/src/client.dart b/lib/src/client.dart index cc81057..7bad12b 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1,9 +1,6 @@ import 'dart:async'; -import 'dart:io'; import 'dart:math'; -import 'package:blip_sdk/src/config.dart'; import 'package:lime/lime.dart'; -import 'package:ssl_pinning_plugin/ssl_pinning_plugin.dart'; import 'application.dart'; import 'extensions/base.extension.dart'; import 'extensions/enums/extension_type.enum.dart'; @@ -17,7 +14,7 @@ class Client { final String uri; final Application application; final Transport transport; - final bool forceSecureConnection; + final bool useMtls; ClientChannel _clientChannel; final _notificationListeners = >[]; @@ -27,7 +24,9 @@ class Client { final _sessionFinishedHandlers = []; final _sessionFailedHandlers = []; final _extensions = {}; - final onListeningChanged = StreamController(); + final onListeningChanged = StreamController(); + + late StreamController onConnectionDone; bool _listening = false; bool _closing = false; @@ -39,7 +38,7 @@ class Client { required this.uri, required this.transport, required this.application, - this.forceSecureConnection = false, + this.useMtls = false, }) : _clientChannel = ClientChannel(transport) { _initializeClientChannel(); } @@ -52,7 +51,8 @@ class Client { } /// Allows connection with an identifier and password - Future connectWithPassword(String identifier, String password, {Presence? presence}) { + Future connectWithPassword(String identifier, String password, + {Presence? presence}) { application.identifier = identifier; application.authentication = PlainAuthentication(password: password); @@ -61,7 +61,8 @@ class Client { } /// Allows connection with an identifier and key - Future connectWithKey(String identifier, String key, {Presence? presence}) { + Future connectWithKey(String identifier, String key, + {Presence? presence}) { application.identifier = identifier; application.authentication = KeyAuthentication(key: key); @@ -72,23 +73,6 @@ class Client { /// Starts the process of connecting to the server and establish a session Future connect() async { - if (forceSecureConnection) { - const wssProtocol = 'wss://'; - const httpsProtocol = 'https://'; - var uri = this.uri; - - if (Platform.isAndroid && uri.contains(wssProtocol)) { - uri = uri.replaceFirst(wssProtocol, httpsProtocol); - } - - await SslPinningPlugin.check( - serverURL: uri, - sha: SHA.SHA256, - allowedSHAFingerprints: Config.allowedFingerprints, - timeout: 300, - ); - } - if (_connectionTryCount >= maxConnectionTryCount) { throw Exception( 'Could not connect: Max connection try count of $maxConnectionTryCount reached. Please check you network and refresh the page.'); @@ -97,7 +81,7 @@ class Client { _connectionTryCount++; _closing = false; return transport - .open(uri) + .open(uri, useMtls: useMtls) .then( (_) => _clientChannel.establishSession( application.identifier + '@' + application.domain, @@ -129,6 +113,9 @@ class Client { transport.onEnvelope?.close(); transport.onEnvelope = StreamController>(); + transport.onConnectionDone?.close(); + transport.onConnectionDone = StreamController(); + transport.onClose.close(); transport.onClose = StreamController(); @@ -206,6 +193,8 @@ class Client { stream.sink.add(session); } }); + + onConnectionDone = _clientChannel.onConnectionDone; } /// Notifies the [Message] listeners with the received [Message] @@ -298,6 +287,7 @@ class Client { if (_clientChannel.state == SessionState.established) { final result = await _clientChannel.sendFinishingSession(); onListeningChanged.close(); + onConnectionDone.close(); await transport.close(); @@ -390,7 +380,8 @@ class Client { } /// Allow to add a new [Command] listeners, returns a function that can be called to delete this listener from the list - void Function() addCommandListener(StreamController stream, {bool Function(Command)? filter}) { + void Function() addCommandListener(StreamController stream, + {bool Function(Command)? filter}) { _commandListeners.add(Listener(stream, filter: filter)); return () { @@ -457,7 +448,8 @@ class Client { } /// A function to filter a listener - bool Function(Listener) filterListener(StreamController stream, bool Function(T)? filter) { + bool Function(Listener) filterListener( + StreamController stream, bool Function(T)? filter) { return (Listener l) => l.stream == stream && l.filter == filter; } @@ -493,5 +485,6 @@ class Client { } /// Returns a media extension - MediaExtension get media => _getExtension(ExtensionType.media, application.domain); + MediaExtension get media => + _getExtension(ExtensionType.media, application.domain); } diff --git a/lib/src/client_builder.dart b/lib/src/client_builder.dart index afa5994..5180e57 100644 --- a/lib/src/client_builder.dart +++ b/lib/src/client_builder.dart @@ -5,136 +5,137 @@ import 'client.dart'; class ClientBuilder { Application application; Transport transport; - bool forceSecureConnection; + bool useMtls; ClientBuilder({ required this.transport, - this.forceSecureConnection = false, + this.useMtls = false, }) : application = Application(); /// Allows you to set a custom application for configuration - ClientBuilder withApplication(Application application) { + ClientBuilder withApplication(final Application application) { this.application = application; return this; } /// Sets a identifier - ClientBuilder withIdentifier(String identifier) { + ClientBuilder withIdentifier(final String identifier) { application.identifier = identifier; return this; } /// Sets an instance - ClientBuilder withInstance(String instance) { + ClientBuilder withInstance(final String instance) { application.instance = instance; return this; } /// Sets a domain - ClientBuilder withDomain(String domain) { + ClientBuilder withDomain(final String domain) { application.domain = domain; return this; } /// Sets a scheme - ClientBuilder withScheme(String scheme) { + ClientBuilder withScheme(final String scheme) { application.scheme = scheme; return this; } /// Sets a host name - ClientBuilder withHostName(String hostName) { + ClientBuilder withHostName(final String hostName) { application.hostName = hostName; return this; } /// Sets a port - ClientBuilder withPort(int port) { + ClientBuilder withPort(final int port) { application.port = port; return this; } /// Sets authentication to [KeyAuthentication] type - ClientBuilder withAccessKey(String accessKey) { + ClientBuilder withAccessKey(final String accessKey) { application.authentication = KeyAuthentication(key: accessKey); return this; } /// Sets authentication to [PlainAuthentication] type - ClientBuilder withPassword(String password) { + ClientBuilder withPassword(final String password) { application.authentication = PlainAuthentication(password: password); return this; } /// Sets authentication to [ExternalAuthentication] type - ClientBuilder withToken(String token, String issuer) { + ClientBuilder withToken(final String token, final String issuer) { application.authentication = ExternalAuthentication(token: token, issuer: issuer); return this; } /// Sets the [SessionCompression] - ClientBuilder withCompression(SessionCompression compression) { + ClientBuilder withCompression(final SessionCompression compression) { application.compression = compression; return this; } /// Sets the [SessionEncryption] - ClientBuilder withEncryption(SessionEncryption encryption) { + ClientBuilder withEncryption(final SessionEncryption encryption) { application.encryption = encryption; return this; } /// Sets the presence routing rule - ClientBuilder withRoutingRule(RoutingRule routingRule) { + ClientBuilder withRoutingRule(final RoutingRule routingRule) { application.presence.routingRule = routingRule; return this; } /// Sets the presence echo - ClientBuilder withEcho(bool echo) { + ClientBuilder withEcho(final bool echo) { application.presence.echo = echo; return this; } /// Sets the presence priority - ClientBuilder withPriority(int priority) { + ClientBuilder withPriority(final int priority) { application.presence.priority = priority; return this; } /// Sets the presence round robin - ClientBuilder withRoundRobin(bool roundRobin) { + ClientBuilder withRoundRobin(final bool roundRobin) { application.presence.roundRobin = roundRobin; return this; } /// Send a [Notification] when consume the [Message] - ClientBuilder withNotifyConsumed(bool notifyConsumed) { + ClientBuilder withNotifyConsumed(final bool notifyConsumed) { application.notifyConsumed = notifyConsumed; return this; } /// Set a default timeout - ClientBuilder withCommandTimeout(int timeoutInMilliSecs) { + ClientBuilder withCommandTimeout(final int timeoutInMilliSecs) { application.commandTimeout = timeoutInMilliSecs; return this; } - + /// Set a secure connection - ClientBuilder withSecureConnection() { - forceSecureConnection = true; + ClientBuilder withMtls(final bool? useMtls) { + this.useMtls = useMtls ?? false; return this; } /// Returns a new instance of SDK Client Client build() { - final uri = '${application.scheme}://${application.hostName}:${application.port}'; + final uri = + '${application.scheme}://${application.hostName}:${application.port}'; return Client( uri: uri, transport: transport, application: application, - forceSecureConnection: forceSecureConnection, + useMtls: useMtls, ); } } diff --git a/pubspec.lock b/pubspec.lock index 134ae1b..a6cef19 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,28 +21,21 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" crypto: dependency: transitive description: @@ -56,7 +49,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -80,7 +73,7 @@ packages: name: lime url: "https://pub.dartlang.org" source: hosted - version: "0.0.15" + version: "0.0.17" lints: dependency: transitive description: @@ -101,28 +94,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" pretty_json: dependency: transitive description: @@ -148,7 +141,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -169,21 +162,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.12" typed_data: dependency: transitive description: @@ -204,7 +197,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index 29d89ed..55c05cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,17 @@ name: blip_sdk description: A simple SDK built for BLiP using Flutter/Dart -version: 0.0.17 +version: 0.0.18 homepage: https://github.com/takenet/blip-sdk-dart#readme repository: https://github.com/takenet/blip-sdk-dart environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + sdk: '>=2.12.0 <3.0.0' + flutter: '>=1.17.0' dependencies: flutter: sdk: flutter - lime: ^0.0.15 + lime: ^0.0.17 dev_dependencies: flutter_test: