@@ -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 ) {
0 commit comments