From 84668b458137f51c130f97fc0e8e4ee5d8f99b82 Mon Sep 17 00:00:00 2001 From: gertdrui Date: Tue, 26 Jan 2021 16:16:20 +0200 Subject: [PATCH 1/6] re-register listener on each connect, dont keep adding new listeners on native android on each connect --- .../chinloyal/pusher_client/pusher/PusherService.kt | 10 ++++++++-- lib/src/contracts/stream_handler.dart | 2 ++ lib/src/pusher/pusher_client.dart | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt index 5fea015..a1a3e2e 100644 --- a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt +++ b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt @@ -29,6 +29,7 @@ const val PRESENCE_PREFIX = "presence-" class PusherService : MChannel { private var _pusherInstance: Pusher? = null + private var _connectionListener: ConnectionListener = ConnectionListener() companion object { var enableLogging: Boolean = false @@ -120,7 +121,12 @@ class PusherService : MChannel { } private fun connect(result: Result) { - _pusherInstance?.connect(ConnectionListener(), ConnectionState.ALL) + _pusherInstance?.connect(_connectionListener, ConnectionState.ALL) + result.success(null) + } + + private fun reconnect(result: Result) { + _pusherInstance?.connect() result.success(null) } @@ -174,7 +180,7 @@ class PusherService : MChannel { private fun unsubscribe(call: MethodCall, result: Result) { try { val src = call.arguments as Map - val args = JSONObject(src); + val args = JSONObject(src) val channelName = args.getString("channelName") _pusherInstance?.unsubscribe(channelName) diff --git a/lib/src/contracts/stream_handler.dart b/lib/src/contracts/stream_handler.dart index 0ad1245..5d2f8fa 100644 --- a/lib/src/contracts/stream_handler.dart +++ b/lib/src/contracts/stream_handler.dart @@ -12,6 +12,8 @@ abstract class StreamHandler { /// Add a listener to the event channel stream for pusher, /// any class that extends [StreamHandler] should use this method. void registerListener(String classId, dynamic Function(dynamic) method) { + _eventStreamSubscription?.cancel(); + StreamHandler._listeners[classId] = method; _eventStreamSubscription = diff --git a/lib/src/pusher/pusher_client.dart b/lib/src/pusher/pusher_client.dart index 842f174..d48d029 100644 --- a/lib/src/pusher/pusher_client.dart +++ b/lib/src/pusher/pusher_client.dart @@ -57,7 +57,6 @@ class PusherClient extends StreamHandler { } Future _init(String appKey, PusherOptions options, InitArgs initArgs) async { - registerListener(classId, _eventHandler); await _channel.invokeMethod( 'init', jsonEncode({ @@ -89,6 +88,8 @@ class PusherClient extends StreamHandler { /// Initiates a connection attempt using the client's /// existing connection details Future connect() async { + registerListener(classId, _eventHandler); + await _channel.invokeMethod('connect'); } From 98ee6baabffce8d4d3ff2b72f0e76070d40cb055 Mon Sep 17 00:00:00 2001 From: gertdrui Date: Tue, 26 Jan 2021 16:27:41 +0200 Subject: [PATCH 2/6] fix listener on init --- .../github/chinloyal/pusher_client/pusher/PusherService.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt index a1a3e2e..48a1114 100644 --- a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt +++ b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt @@ -29,7 +29,7 @@ const val PRESENCE_PREFIX = "presence-" class PusherService : MChannel { private var _pusherInstance: Pusher? = null - private var _connectionListener: ConnectionListener = ConnectionListener() + private var _connectionListener: ConnectionListener? = null companion object { var enableLogging: Boolean = false @@ -76,6 +76,8 @@ class PusherService : MChannel { } private fun init(call: MethodCall, result: Result) { + _connectionListener = ConnectionListener() + // toString works because this is json encoded in dart val args = JSONObject(call.arguments.toString()) val initArgs: JSONObject = args.getJSONObject("initArgs") From adbe3290807ec5230781805c09d2e40e7be51fd3 Mon Sep 17 00:00:00 2001 From: gertdrui Date: Tue, 26 Jan 2021 16:48:00 +0200 Subject: [PATCH 3/6] undo previous change --- .../github/chinloyal/pusher_client/pusher/PusherService.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt index 48a1114..c8fc718 100644 --- a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt +++ b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt @@ -29,7 +29,7 @@ const val PRESENCE_PREFIX = "presence-" class PusherService : MChannel { private var _pusherInstance: Pusher? = null - private var _connectionListener: ConnectionListener? = null + private var _connectionListener: ConnectionListener? = ConnectionListener() companion object { var enableLogging: Boolean = false @@ -76,8 +76,6 @@ class PusherService : MChannel { } private fun init(call: MethodCall, result: Result) { - _connectionListener = ConnectionListener() - // toString works because this is json encoded in dart val args = JSONObject(call.arguments.toString()) val initArgs: JSONObject = args.getJSONObject("initArgs") From 045bfa9bfe51746d20cc2db2a8dc8a9d3cd63941 Mon Sep 17 00:00:00 2001 From: gertdrui Date: Tue, 26 Jan 2021 17:03:49 +0200 Subject: [PATCH 4/6] remove unused code --- .../github/chinloyal/pusher_client/pusher/PusherService.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt index c8fc718..2aee1aa 100644 --- a/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt +++ b/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt @@ -125,11 +125,6 @@ class PusherService : MChannel { result.success(null) } - private fun reconnect(result: Result) { - _pusherInstance?.connect() - result.success(null) - } - private fun disconnect(result: Result) { _pusherInstance?.disconnect() debugLog("Disconnect") From d0c74905b2bc34a035f49072344abd531240cbe0 Mon Sep 17 00:00:00 2001 From: Mochamad Nizwar Syafuan Date: Wed, 7 Apr 2021 14:26:38 +0700 Subject: [PATCH 5/6] Null Safety --- example/pubspec.lock | 42 +++++++++---------- lib/src/contracts/stream_handler.dart | 9 ++-- lib/src/models/connection_error.dart | 6 +-- lib/src/models/connection_error.g.dart | 6 +-- lib/src/models/connection_state_change.dart | 4 +- lib/src/models/connection_state_change.g.dart | 4 +- lib/src/models/event_stream_result.dart | 6 +-- lib/src/pusher/channel.dart | 8 ++-- lib/src/pusher/pusher_auth.dart | 4 +- lib/src/pusher/pusher_auth.g.dart | 4 +- lib/src/pusher/pusher_client.dart | 26 ++++++------ lib/src/pusher/pusher_event.dart | 8 ++-- lib/src/pusher/pusher_event.g.dart | 8 ++-- lib/src/pusher/pusher_options.dart | 20 ++++----- lib/src/pusher/pusher_options.g.dart | 18 ++++---- pubspec.lock | 40 +++++++++--------- pubspec.yaml | 4 +- 17 files changed, 107 insertions(+), 110 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index aeca109..7a13cf4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -73,28 +73,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" pusher_client: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.1.3" + version: "1.1.4" sky_engine: dependency: transitive description: flutter @@ -106,56 +106,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/lib/src/contracts/stream_handler.dart b/lib/src/contracts/stream_handler.dart index 0ad1245..4b51915 100644 --- a/lib/src/contracts/stream_handler.dart +++ b/lib/src/contracts/stream_handler.dart @@ -3,9 +3,8 @@ import 'dart:async'; import 'package:flutter/services.dart'; abstract class StreamHandler { - static const EventChannel _eventStream = - const EventChannel('com.github.chinloyal/pusher_client_stream'); - StreamSubscription _eventStreamSubscription; + static const EventChannel _eventStream = const EventChannel('com.github.chinloyal/pusher_client_stream'); + late StreamSubscription _eventStreamSubscription; static Map _listeners = {}; @@ -13,9 +12,7 @@ abstract class StreamHandler { /// any class that extends [StreamHandler] should use this method. void registerListener(String classId, dynamic Function(dynamic) method) { StreamHandler._listeners[classId] = method; - - _eventStreamSubscription = - _eventStream.receiveBroadcastStream().listen(_eventHandler); + _eventStreamSubscription = _eventStream.receiveBroadcastStream().listen(_eventHandler); } /// This method will close the entire event channel stream diff --git a/lib/src/models/connection_error.dart b/lib/src/models/connection_error.dart index c4d5ce2..2d6303e 100644 --- a/lib/src/models/connection_error.dart +++ b/lib/src/models/connection_error.dart @@ -2,13 +2,13 @@ part 'connection_error.g.dart'; class ConnectionError { /// A message indicating the cause of the error. - final String message; + final String? message; /// The error code for the message. Can be null. - final String code; + final String? code; /// The exception that was thrown, if any. Can be null. - final String exception; + final String? exception; ConnectionError({this.message, this.code, this.exception}); diff --git a/lib/src/models/connection_error.g.dart b/lib/src/models/connection_error.g.dart index c724043..d284ec6 100644 --- a/lib/src/models/connection_error.g.dart +++ b/lib/src/models/connection_error.g.dart @@ -4,9 +4,9 @@ part of 'connection_error.dart'; ConnectionError _$ConnectionErrorFromJson(Map json) { return ConnectionError( - message: json['message'] as String, - code: json['code'] as String, - exception: json['exception'] as String, + message: json['message'] as String?, + code: json['code'] as String?, + exception: json['exception'] as String?, ); } diff --git a/lib/src/models/connection_state_change.dart b/lib/src/models/connection_state_change.dart index 2e92e73..5a395a5 100644 --- a/lib/src/models/connection_state_change.dart +++ b/lib/src/models/connection_state_change.dart @@ -3,11 +3,11 @@ part 'connection_state_change.g.dart'; class ConnectionStateChange { /// The current connection state. The state the connection has transitioned /// to. - final String currentState; + final String? currentState; /// The previous connections state. The state the connection has transitioned /// from. - final String previousState; + final String? previousState; ConnectionStateChange({ this.currentState, diff --git a/lib/src/models/connection_state_change.g.dart b/lib/src/models/connection_state_change.g.dart index 1834bec..7325ea4 100644 --- a/lib/src/models/connection_state_change.g.dart +++ b/lib/src/models/connection_state_change.g.dart @@ -5,8 +5,8 @@ part of 'connection_state_change.dart'; ConnectionStateChange _$ConnectionStateChangeFromJson( Map json) { return ConnectionStateChange( - currentState: json['currentState'] as String, - previousState: json['previousState'] as String, + currentState: json['currentState'] as String?, + previousState: json['previousState'] as String?, ); } diff --git a/lib/src/models/event_stream_result.dart b/lib/src/models/event_stream_result.dart index 1342b95..6d45911 100644 --- a/lib/src/models/event_stream_result.dart +++ b/lib/src/models/event_stream_result.dart @@ -5,9 +5,9 @@ import 'package:pusher_client/src/pusher/pusher_event.dart'; part 'event_stream_result.g.dart'; class EventStreamResult { - final ConnectionStateChange connectionStateChange; - final ConnectionError connectionError; - final PusherEvent pusherEvent; + final ConnectionStateChange? connectionStateChange; + final ConnectionError? connectionError; + final PusherEvent? pusherEvent; EventStreamResult({ this.connectionStateChange, diff --git a/lib/src/pusher/channel.dart b/lib/src/pusher/channel.dart index 3452cc4..9bf4df9 100644 --- a/lib/src/pusher/channel.dart +++ b/lib/src/pusher/channel.dart @@ -11,8 +11,8 @@ class Channel extends StreamHandler { const MethodChannel('com.github.chinloyal/pusher_client'); static const classId = 'Channel'; - static Map _eventCallbacks = - Map(); + static Map _eventCallbacks = + Map(); final String name; @@ -31,7 +31,7 @@ class Channel extends StreamHandler { /// [eventName] is received on this channel. Future bind( String eventName, - void Function(PusherEvent event) onEvent, + void Function(PusherEvent? event) onEvent, ) async { registerListener(classId, _eventHandler); _eventCallbacks[this.name + eventName] = onEvent; @@ -80,7 +80,7 @@ class Channel extends StreamHandler { if (result.isPusherEvent) { var callback = _eventCallbacks[ - result.pusherEvent.channelName + result.pusherEvent.eventName]; + result.pusherEvent!.channelName! + result.pusherEvent!.eventName!]; if (callback != null) { callback(result.pusherEvent); } diff --git a/lib/src/pusher/pusher_auth.dart b/lib/src/pusher/pusher_auth.dart index 90cd519..308f879 100644 --- a/lib/src/pusher/pusher_auth.dart +++ b/lib/src/pusher/pusher_auth.dart @@ -2,10 +2,10 @@ part 'pusher_auth.g.dart'; class PusherAuth { /// The endpoint to be called when authenticating. - final String endpoint; + final String? endpoint; /// Additional headers to be sent as part of the request. - final Map headers; + final Map? headers; PusherAuth( this.endpoint, { diff --git a/lib/src/pusher/pusher_auth.g.dart b/lib/src/pusher/pusher_auth.g.dart index 15a8f1b..64d20b7 100644 --- a/lib/src/pusher/pusher_auth.g.dart +++ b/lib/src/pusher/pusher_auth.g.dart @@ -4,8 +4,8 @@ part of 'pusher_auth.dart'; PusherAuth _$PusherAuthFromJson(Map json) { return PusherAuth( - json['endpoint'] as String, - headers: (json['headers'] as Map)?.map( + json['endpoint'] as String?, + headers: (json['headers'] as Map?)?.map( (k, e) => MapEntry(k, e as String), ), ); diff --git a/lib/src/pusher/pusher_client.dart b/lib/src/pusher/pusher_client.dart index 842f174..4394608 100644 --- a/lib/src/pusher/pusher_client.dart +++ b/lib/src/pusher/pusher_client.dart @@ -21,10 +21,10 @@ class PusherClient extends StreamHandler { const MethodChannel('com.github.chinloyal/pusher_client'); static const classId = 'PusherClient'; - static PusherClient _singleton; - void Function(ConnectionStateChange) _onConnectionStateChange; - void Function(ConnectionError) _onConnectionError; - String _socketId; + static PusherClient? _singleton; + void Function(ConnectionStateChange?)? _onConnectionStateChange; + void Function(ConnectionError?)? _onConnectionError; + String? _socketId; PusherClient._( String appKey, @@ -49,11 +49,11 @@ class PusherClient extends StreamHandler { final initArgs = InitArgs(enableLogging: enableLogging); - _singleton._init(appKey, options, initArgs); + _singleton!._init(appKey, options, initArgs); - if (autoConnect) _singleton.connect(); + if (autoConnect) _singleton!.connect(); - return _singleton; + return _singleton!; } Future _init(String appKey, PusherOptions options, InitArgs initArgs) async { @@ -100,20 +100,20 @@ class PusherClient extends StreamHandler { } /// The id of the current connection - String getSocketId() => _socketId; + String? getSocketId() => _socketId; /// Callback that is fired whenever the connection state of the /// connection changes. The state typically changes during connection /// to Pusher and during disconnection and reconnection. void onConnectionStateChange( - void Function(ConnectionStateChange state) callback) { + void Function(ConnectionStateChange? state) callback) { _onConnectionStateChange = callback; } /// Callback that indicates either: /// - An error message has been received from Pusher, or /// - An error has occurred in the client library. - void onConnectionError(void Function(ConnectionError error) callback) { + void onConnectionError(void Function(ConnectionError? error) callback) { _onConnectionError = callback; } @@ -124,18 +124,18 @@ class PusherClient extends StreamHandler { _socketId = await _channel.invokeMethod('getSocketId'); if (_onConnectionStateChange != null) - _onConnectionStateChange(result.connectionStateChange); + _onConnectionStateChange!(result.connectionStateChange); } if (result.isConnectionError) { if (_onConnectionError != null) - _onConnectionError(result.connectionError); + _onConnectionError!(result.connectionError); } } } class InitArgs { - final bool enableLogging; + final bool? enableLogging; InitArgs({ this.enableLogging, diff --git a/lib/src/pusher/pusher_event.dart b/lib/src/pusher/pusher_event.dart index 4dc376b..2f33bc7 100644 --- a/lib/src/pusher/pusher_event.dart +++ b/lib/src/pusher/pusher_event.dart @@ -4,17 +4,17 @@ class PusherEvent { /// The name of the channel that the event was triggered on. Not present /// in events without an associated channel, For example "pusher:error" events /// relating to the connection. - final String channelName; + final String? channelName; /// The name of the event. - final String eventName; + final String? eventName; /// The data that was passed when the event was triggered. - final String data; + final String? data; /// The ID of the user who triggered the event. Only present in /// client event on presence channels. - final String userId; + final String? userId; PusherEvent({ this.channelName, diff --git a/lib/src/pusher/pusher_event.g.dart b/lib/src/pusher/pusher_event.g.dart index ca4cfd4..4032c8f 100644 --- a/lib/src/pusher/pusher_event.g.dart +++ b/lib/src/pusher/pusher_event.g.dart @@ -4,10 +4,10 @@ part of 'pusher_event.dart'; PusherEvent _$PusherEventFromJson(Map json) { return PusherEvent( - channelName: json['channelName'] as String, - eventName: json['eventName'] as String, - data: json['data'] as String, - userId: json['userId'] as String, + channelName: json['channelName'] as String?, + eventName: json['eventName'] as String?, + data: json['data'] as String?, + userId: json['userId'] as String?, ); } diff --git a/lib/src/pusher/pusher_options.dart b/lib/src/pusher/pusher_options.dart index 48c2251..81dc222 100644 --- a/lib/src/pusher/pusher_options.dart +++ b/lib/src/pusher/pusher_options.dart @@ -5,44 +5,44 @@ part 'pusher_options.g.dart'; class PusherOptions { /// Sets the authorization options to be used when authenticating private, /// private-encrypted and presence channels. - final PusherAuth auth; + final PusherAuth? auth; /// A "cluster" represents the physical location of the servers that handle /// requests from your Channels app. /// /// For example, the Channels cluster `mt1` is in Northern Virginia /// in the United States. - final String cluster; + final String? cluster; /// The host to which connections will be made. - final String host; + final String? host; /// Whether the connection to Pusher should be use TLS. - final bool encrypted; + final bool? encrypted; /// The number of milliseconds of inactivity at which a "ping" will be /// triggered to check the connection. - final int activityTimeout; + final int? activityTimeout; /// The port to which non TLS connections will be made. - final int wsPort; + final int? wsPort; /// The port to which encrypted connections will be made. - final int wssPort; + final int? wssPort; /// The number of milliseconds after a "ping" is sent that the client will /// wait to receive a "pong" response from the server before considering the /// connection broken and triggering a transition to the disconnected state. /// /// The default value is 30,000. - final int pongTimeout; + final int? pongTimeout; /// Number of reconnect attempts when websocket connection failed - final int maxReconnectionAttempts; + final int? maxReconnectionAttempts; /// The delay in two reconnection extends exponentially (1, 2, 4, .. seconds) /// This property sets the maximum in between two reconnection attempts. - final int maxReconnectGapInSeconds; + final int? maxReconnectGapInSeconds; PusherOptions({ this.auth, diff --git a/lib/src/pusher/pusher_options.g.dart b/lib/src/pusher/pusher_options.g.dart index ebafe00..8f93712 100644 --- a/lib/src/pusher/pusher_options.g.dart +++ b/lib/src/pusher/pusher_options.g.dart @@ -7,15 +7,15 @@ PusherOptions _$PusherOptionsFromJson(Map json) { auth: json['auth'] == null ? null : PusherAuth.fromJson(json['auth'] as Map), - cluster: json['cluster'] as String, - host: json['host'] as String, - wsPort: json['wsPort'] as int, - wssPort: json['wssPort'] as int, - encrypted: json['encrypted'] as bool, - activityTimeout: json['activityTimeout'] as int, - pongTimeout: json['pongTimeout'] as int, - maxReconnectionAttempts: json['maxReconnectionAttempts'] as int, - maxReconnectGapInSeconds: json['maxReconnectGapInSeconds'] as int, + cluster: json['cluster'] as String?, + host: json['host'] as String?, + wsPort: json['wsPort'] as int?, + wssPort: json['wssPort'] as int?, + encrypted: json['encrypted'] as bool?, + activityTimeout: json['activityTimeout'] as int?, + pongTimeout: json['pongTimeout'] as int?, + maxReconnectionAttempts: json['maxReconnectionAttempts'] as int?, + maxReconnectGapInSeconds: json['maxReconnectGapInSeconds'] as int?, ); } diff --git a/pubspec.lock b/pubspec.lock index 89ec533..96b4a33 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index ad11ab0..5aba00b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,13 +2,13 @@ name: pusher_client description: | A Pusher Channels client plugin for Flutter targeting Android and iOS. It wraps pusher-websocket-java v2.2.5 and pusher-websocket-swift v8.0.0. -version: 1.1.3 +version: 1.1.4 homepage: https://github.com/chinloyal/pusher_client documentation: https://github.com/chinloyal/pusher_client/blob/master/README.md environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.20.0 <2.0.0" dependencies: From bd7fc1324c86daf7c5824ca5f6ea6d12454e315d Mon Sep 17 00:00:00 2001 From: gertdrui Date: Mon, 24 May 2021 12:01:37 +0300 Subject: [PATCH 6/6] fix nullsafety --- example/pubspec.lock | 8 ++++---- lib/src/contracts/stream_handler.dart | 10 ++++++---- lib/src/pusher/channel.dart | 5 +++-- pubspec.lock | 8 ++++---- pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 7a13cf4..10abd0b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -106,7 +106,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -141,7 +141,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: @@ -157,5 +157,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.13.0 <3.0.0" flutter: ">=1.20.0" diff --git a/lib/src/contracts/stream_handler.dart b/lib/src/contracts/stream_handler.dart index 0c508c5..31b94b8 100644 --- a/lib/src/contracts/stream_handler.dart +++ b/lib/src/contracts/stream_handler.dart @@ -3,8 +3,9 @@ import 'dart:async'; import 'package:flutter/services.dart'; abstract class StreamHandler { - static const EventChannel _eventStream = const EventChannel('com.github.chinloyal/pusher_client_stream'); - late StreamSubscription _eventStreamSubscription; + static const EventChannel _eventStream = + const EventChannel('com.github.chinloyal/pusher_client_stream'); + StreamSubscription? _eventStreamSubscription; static Map _listeners = {}; @@ -14,13 +15,14 @@ abstract class StreamHandler { _eventStreamSubscription?.cancel(); StreamHandler._listeners[classId] = method; - _eventStreamSubscription = _eventStream.receiveBroadcastStream().listen(_eventHandler); + _eventStreamSubscription = + _eventStream.receiveBroadcastStream().listen(_eventHandler); } /// This method will close the entire event channel stream /// which is why it should only be used by [PusherClient] void cancelEventChannelStream() { - _eventStreamSubscription.cancel(); + _eventStreamSubscription?.cancel(); } void _eventHandler(event) { diff --git a/lib/src/pusher/channel.dart b/lib/src/pusher/channel.dart index 9bf4df9..eee08aa 100644 --- a/lib/src/pusher/channel.dart +++ b/lib/src/pusher/channel.dart @@ -6,13 +6,14 @@ import 'package:pusher_client/src/contracts/stream_handler.dart'; import 'package:pusher_client/src/models/event_stream_result.dart'; import 'package:pusher_client/src/pusher/pusher_event.dart'; +typedef EventCallback = Map; + class Channel extends StreamHandler { static const MethodChannel _mChannel = const MethodChannel('com.github.chinloyal/pusher_client'); static const classId = 'Channel'; - static Map _eventCallbacks = - Map(); + static EventCallback _eventCallbacks = EventCallback(); final String name; diff --git a/pubspec.lock b/pubspec.lock index 96b4a33..1eaf6ca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -92,7 +92,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -127,7 +127,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: @@ -143,5 +143,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.13.0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5aba00b..e33fccc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ documentation: https://github.com/chinloyal/pusher_client/blob/master/README.md environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.13.0 <3.0.0' flutter: ">=1.20.0 <2.0.0" dependencies: