Skip to content

Commit dc704c2

Browse files
committed
Add another example of using AuthRequestBuilderProtocol to iOS example
(Swift) so that there are examples of the old, deprecated method, as well as the newly added one
1 parent 5af1bd6 commit dc704c2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

iOS Example Swift/iOS Example Swift/ViewController.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ class ViewController: UIViewController, PusherDelegate {
2525

2626
// Only use your secret here for testing or if you're sure that there's
2727
// 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)
3030

31-
// Use this if you want to try out your auth endpoint
31+
// // Use this if you want to try out your auth endpoint
3232
// let optionsWithEndpoint = PusherClientOptions(
3333
// authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder())
3434
// )
3535
// pusher = Pusher(key: "YOUR_APP_KEY", options: optionsWithEndpoint)
3636

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+
3743
pusher.delegate = self
3844

3945
pusher.connect()
@@ -83,11 +89,20 @@ class ViewController: UIViewController, PusherDelegate {
8389
}
8490
}
8591

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+
86101
class AuthRequestBuilder: AuthRequestBuilderProtocol {
87-
func requestFor(socketID: String, channel: PusherChannel) -> URLRequest? {
102+
func requestFor(socketID: String, channelName: String) -> URLRequest? {
88103
var request = URLRequest(url: URL(string: "http://localhost:9292/pusher/auth")!)
89104
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)
91106
return request
92107
}
93108
}

0 commit comments

Comments
 (0)