@@ -25,15 +25,21 @@ class ViewController: UIViewController, PusherDelegate {
25
25
26
26
// Only use your secret here for testing or if you're sure that there's
27
27
// no security risk
28
- let pusherClientOptions = PusherClientOptions ( authMethod: . inline( secret: " YOUR_APP_SECRET " ) )
29
- pusher = Pusher ( key: " YOUR_APP_KEY " , options: pusherClientOptions)
28
+ // let pusherClientOptions = PusherClientOptions(authMethod: .inline(secret: "YOUR_APP_SECRET"))
29
+ // pusher = Pusher(key: "YOUR_APP_KEY", options: pusherClientOptions)
30
30
31
- // Use this if you want to try out your auth endpoint
31
+ // // Use this if you want to try out your auth endpoint
32
32
// let optionsWithEndpoint = PusherClientOptions(
33
33
// authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder())
34
34
// )
35
35
// pusher = Pusher(key: "YOUR_APP_KEY", options: optionsWithEndpoint)
36
36
37
+ // Use this if you want to try out your auth endpoint (deprecated method)
38
+ let optionsWithEndpoint = PusherClientOptions (
39
+ authMethod: AuthMethod . authRequestBuilder ( authRequestBuilder: AuthRequestBuilderOld ( ) )
40
+ )
41
+ pusher = Pusher ( key: " YOUR_APP_KEY " , options: optionsWithEndpoint)
42
+
37
43
pusher. delegate = self
38
44
39
45
pusher. connect ( )
@@ -83,11 +89,20 @@ class ViewController: UIViewController, PusherDelegate {
83
89
}
84
90
}
85
91
92
+ class AuthRequestBuilderOld : AuthRequestBuilderProtocol {
93
+ func requestFor( socketID: String , channel: PusherChannel ) -> NSMutableURLRequest ? {
94
+ let request = NSMutableURLRequest ( url: URL ( string: " http://localhost:9292/pusher/auth " ) !)
95
+ request. httpMethod = " POST "
96
+ request. httpBody = " socket_id= \( socketID) &channel_name= \( channel. name) " . data ( using: String . Encoding. utf8)
97
+ return request
98
+ }
99
+ }
100
+
86
101
class AuthRequestBuilder : AuthRequestBuilderProtocol {
87
- func requestFor( socketID: String , channel : PusherChannel ) -> URLRequest ? {
102
+ func requestFor( socketID: String , channelName : String ) -> URLRequest ? {
88
103
var request = URLRequest ( url: URL ( string: " http://localhost:9292/pusher/auth " ) !)
89
104
request. httpMethod = " POST "
90
- request. httpBody = " socket_id= \( socketID) &channel_name= \( channel . name ) " . data ( using: String . Encoding. utf8)
105
+ request. httpBody = " socket_id= \( socketID) &channel_name= \( channelName ) " . data ( using: String . Encoding. utf8)
91
106
return request
92
107
}
93
108
}
0 commit comments