Skip to content

Commit 0a0cbcf

Browse files
proggen-comdaansystemspusher-ci
authored
Allow reinit (#80)
* allow reinit of pusher * allow reinit of pusher-js * Bump to version 2.1.0 Co-authored-by: Niek <[email protected]> Co-authored-by: Pusher CI <[email protected]>
1 parent 4cff17d commit 0a0cbcf

File tree

6 files changed

+93
-83
lines changed

6 files changed

+93
-83
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.1.0
4+
5+
* [CHANGED] Allow reinitialization of the pusher singleton
6+
* [CHANGED] Add subscription count event handling ios/android
7+
* [CHANGED] Update flutter dependencies to the latest versions.
8+
39
## 2.0.2
410

511
* [FIXED] Fix private-encrypted channels subscriptions

android/src/main/kotlin/com/pusher/channels_flutter/PusherChannelsFlutterPlugin.kt

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,29 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw
9797
result: Result
9898
) {
9999
try {
100-
if (pusher == null) {
101-
val options = PusherOptions()
102-
if (call.argument<String>("cluster") != null) options.setCluster(call.argument("cluster"))
103-
if (call.argument<Boolean>("useTLS") != null) options.isUseTLS =
104-
call.argument("useTLS")!!
105-
if (call.argument<Long>("activityTimeout") != null) options.activityTimeout =
106-
call.argument("activityTimeout")!!
107-
if (call.argument<Long>("pongTimeout") != null) options.pongTimeout =
108-
call.argument("pongTimeout")!!
109-
if (call.argument<Int>("maxReconnectionAttempts") != null) options.maxReconnectionAttempts =
110-
call.argument("maxReconnectionAttempts")!!
111-
if (call.argument<Int>("maxReconnectGapInSeconds") != null) options.maxReconnectGapInSeconds =
112-
call.argument("maxReconnectGapInSeconds")!!
113-
if (call.argument<String>("authEndpoint") != null) options.channelAuthorizer =
114-
HttpChannelAuthorizer(call.argument("authEndpoint"))
115-
if (call.argument<String>("authorizer") != null) options.channelAuthorizer = this
116-
if (call.argument<String>("proxy") != null) {
117-
val (host, port) = call.argument<String>("proxy")!!.split(':')
118-
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
119-
}
120-
pusher = Pusher(call.argument("apiKey"), options)
121-
} else {
122-
throw Exception("Pusher Channels already initialized.")
100+
if (pusher != null) {
101+
pusher!!.disconnect()
102+
}
103+
val options = PusherOptions()
104+
if (call.argument<String>("cluster") != null) options.setCluster(call.argument("cluster"))
105+
if (call.argument<Boolean>("useTLS") != null) options.isUseTLS =
106+
call.argument("useTLS")!!
107+
if (call.argument<Long>("activityTimeout") != null) options.activityTimeout =
108+
call.argument("activityTimeout")!!
109+
if (call.argument<Long>("pongTimeout") != null) options.pongTimeout =
110+
call.argument("pongTimeout")!!
111+
if (call.argument<Int>("maxReconnectionAttempts") != null) options.maxReconnectionAttempts =
112+
call.argument("maxReconnectionAttempts")!!
113+
if (call.argument<Int>("maxReconnectGapInSeconds") != null) options.maxReconnectGapInSeconds =
114+
call.argument("maxReconnectGapInSeconds")!!
115+
if (call.argument<String>("authEndpoint") != null) options.channelAuthorizer =
116+
HttpChannelAuthorizer(call.argument("authEndpoint"))
117+
if (call.argument<String>("authorizer") != null) options.channelAuthorizer = this
118+
if (call.argument<String>("proxy") != null) {
119+
val (host, port) = call.argument<String>("proxy")!!.split(':')
120+
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
123121
}
122+
pusher = Pusher(call.argument("apiKey"), options)
124123
Log.i(TAG, "Start $pusher")
125124
result.success(null)
126125
} catch (e: Exception) {

ios/Classes/SwiftPusherChannelsFlutterPlugin.swift

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,66 +35,67 @@ public class SwiftPusherChannelsFlutterPlugin: NSObject, FlutterPlugin, PusherDe
3535
}
3636

3737
func initChannels(call: FlutterMethodCall, result: @escaping FlutterResult) {
38-
if pusher == nil {
39-
let args = call.arguments as! [String: Any]
40-
var authMethod: AuthMethod = .noMethod
41-
if args["authEndpoint"] is String {
42-
authMethod = .endpoint(authEndpoint: args["authEndpoint"] as! String)
43-
} else if args["authorizer"] is Bool {
44-
authMethod = .authorizer(authorizer: self)
45-
}
46-
var host: PusherHost = .defaultHost
47-
if args["host"] is String {
48-
host = .host(args["host"] as! String)
49-
} else if args["cluster"] != nil {
50-
host = .cluster(args["cluster"] as! String)
51-
}
52-
var useTLS: Bool = true
53-
if args["useTLS"] is Bool {
54-
useTLS = args["useTLS"] as! Bool
55-
}
56-
var port: Int
57-
if useTLS {
58-
port = 443
59-
if args["wssPort"] is Int {
60-
port = args["wssPort"] as! Int
61-
}
62-
} else {
63-
port = 80
64-
if args["wsPort"] is Int {
65-
port = args["wsPort"] as! Int
66-
}
67-
}
68-
var activityTimeout: TimeInterval?
69-
if args["activityTimeout"] is TimeInterval {
70-
activityTimeout = args["activityTimeout"] as! Double / 1000.0
71-
}
72-
var path: String?
73-
if args["path"] is String {
74-
path = (args["path"] as! String)
75-
}
76-
let options = PusherClientOptions(
77-
authMethod: authMethod,
78-
host: host,
79-
port: port,
80-
path: path,
81-
useTLS: useTLS,
82-
activityTimeout: activityTimeout
83-
)
84-
pusher = Pusher(key: args["apiKey"] as! String, options: options)
85-
if args["maxReconnectionAttempts"] is Int {
86-
pusher.connection.reconnectAttemptsMax = (args["maxReconnectionAttempts"] as! Int)
87-
}
88-
if args["maxReconnectGapInSeconds"] is TimeInterval {
89-
pusher.connection.maxReconnectGapInSeconds = (args["maxReconnectGapInSeconds"] as! TimeInterval)
38+
if pusher != nil {
39+
pusher.disconnect()
40+
}
41+
let args = call.arguments as! [String: Any]
42+
var authMethod: AuthMethod = .noMethod
43+
if args["authEndpoint"] is String {
44+
authMethod = .endpoint(authEndpoint: args["authEndpoint"] as! String)
45+
} else if args["authorizer"] is Bool {
46+
authMethod = .authorizer(authorizer: self)
47+
}
48+
var host: PusherHost = .defaultHost
49+
if args["host"] is String {
50+
host = .host(args["host"] as! String)
51+
} else if args["cluster"] != nil {
52+
host = .cluster(args["cluster"] as! String)
53+
}
54+
var useTLS: Bool = true
55+
if args["useTLS"] is Bool {
56+
useTLS = args["useTLS"] as! Bool
57+
}
58+
var port: Int
59+
if useTLS {
60+
port = 443
61+
if args["wssPort"] is Int {
62+
port = args["wssPort"] as! Int
9063
}
91-
if args["pongTimeout"] is Int {
92-
pusher.connection.pongResponseTimeoutInterval = args["pongTimeout"] as! TimeInterval / 1000.0
64+
} else {
65+
port = 80
66+
if args["wsPort"] is Int {
67+
port = args["wsPort"] as! Int
9368
}
94-
pusher.connection.delegate = self
95-
pusher.bind(eventCallback: onEvent)
96-
result(nil)
9769
}
70+
var activityTimeout: TimeInterval?
71+
if args["activityTimeout"] is TimeInterval {
72+
activityTimeout = args["activityTimeout"] as! Double / 1000.0
73+
}
74+
var path: String?
75+
if args["path"] is String {
76+
path = (args["path"] as! String)
77+
}
78+
let options = PusherClientOptions(
79+
authMethod: authMethod,
80+
host: host,
81+
port: port,
82+
path: path,
83+
useTLS: useTLS,
84+
activityTimeout: activityTimeout
85+
)
86+
pusher = Pusher(key: args["apiKey"] as! String, options: options)
87+
if args["maxReconnectionAttempts"] is Int {
88+
pusher.connection.reconnectAttemptsMax = (args["maxReconnectionAttempts"] as! Int)
89+
}
90+
if args["maxReconnectGapInSeconds"] is TimeInterval {
91+
pusher.connection.maxReconnectGapInSeconds = (args["maxReconnectGapInSeconds"] as! TimeInterval)
92+
}
93+
if args["pongTimeout"] is Int {
94+
pusher.connection.pongResponseTimeoutInterval = args["pongTimeout"] as! TimeInterval / 1000.0
95+
}
96+
pusher.connection.delegate = self
97+
pusher.bind(eventCallback: onEvent)
98+
result(nil)
9899
}
99100

100101
public func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?) -> Void) {

lib/pusher_channels_flutter_web.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ class PusherChannelsFlutterWeb {
220220
}
221221

222222
void init(MethodCall call) {
223+
if (pusher != null) {
224+
pusher!.unbind_all();
225+
pusher!.disconnect();
226+
}
223227
var options = Options();
224228
if (call.arguments['cluster'] != null) {
225229
options.cluster = call.arguments['cluster'];

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ packages:
7878
name: lints
7979
url: "https://pub.dartlang.org"
8080
source: hosted
81-
version: "2.0.0"
81+
version: "2.0.1"
8282
matcher:
8383
dependency: transitive
8484
description:
@@ -162,5 +162,5 @@ packages:
162162
source: hosted
163163
version: "2.1.2"
164164
sdks:
165-
dart: ">=2.17.0-206.0.dev <3.0.0"
165+
dart: ">=2.17.0 <3.0.0"
166166
flutter: ">=1.20.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: pusher_channels_flutter
22
description: Pusher Channels Flutter Plugin
3-
version: 2.0.2
3+
version: 2.1.0
44
homepage: https://github.com/pusher/pusher-channels-flutter
55
repository: https://github.com/pusher/pusher-channels-flutter
66
issue_tracker: https://github.com/pusher/pusher-channels-flutter/issues

0 commit comments

Comments
 (0)