@@ -90,16 +90,7 @@ public struct PusherClientOptions {
90
90
public let authRequestCustomizer : ( NSMutableURLRequest -> NSMutableURLRequest ) ?
91
91
92
92
public init( options: [ String : Any ] ? ) {
93
- let validKeys = [ " encrypted " , " attemptToReturnJSONObject " , " authEndpoint " , " secret " , " userDataFetcher " , " port " , " host " , " autoReconnect " , " authRequestCustomizer " ]
94
-
95
- if let options = options {
96
- for (key, _) in options {
97
- if !validKeys. contains ( key) {
98
- print ( " Invalid key in options: \( key) " )
99
- }
100
- }
101
- }
102
-
93
+ let validKeys = [ " encrypted " , " attemptToReturnJSONObject " , " authEndpoint " , " secret " , " userDataFetcher " , " port " , " host " , " cluster " , " autoReconnect " , " authRequestCustomizer " ]
103
94
let defaults : [ String : AnyObject ? ] = [
104
95
" encrypted " : true ,
105
96
" attemptToReturnJSONObject " : true ,
@@ -111,10 +102,29 @@ public struct PusherClientOptions {
111
102
" host " : " ws.pusherapp.com " ,
112
103
" port " : nil
113
104
]
105
+
106
+ var mutableOptions = options
107
+
108
+ if let options = options {
109
+ for (key, _) in options {
110
+ if !validKeys. contains ( key) {
111
+ print ( " Invalid key in options: \( key) " )
112
+ }
113
+ }
114
+
115
+ if let cluster = options [ " cluster " ] {
116
+ if let host = options [ " host " ] {
117
+ print ( " Both host ( \( host) ) and cluster ( \( cluster) ) passed as options - host takes precedence " )
118
+ } else {
119
+ mutableOptions![ " host " ] = " ws- \( cluster) .pusher.com "
120
+ }
121
+ }
122
+ }
123
+
124
+ var optionsMergedWithDefaults : [ String : Any ? ] = [ : ]
114
125
115
- var optionsMergedWithDefaults : [ String : Any ] = [ : ]
116
126
for ( key, value) in defaults {
117
- if let options = options , optionsValue = options [ key] {
127
+ if let mutableOptions = mutableOptions , optionsValue = mutableOptions [ key] {
118
128
optionsMergedWithDefaults [ key] = optionsValue
119
129
} else {
120
130
optionsMergedWithDefaults [ key] = value
0 commit comments