File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed
iOS Example Obj-C/iOS Example Obj-C
iOS Example Swift/iOS Example Swift Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 8
8
9
9
#import " ViewController.h"
10
10
11
+ @interface AuthRequestBuilder : NSObject <AuthRequestBuilderProtocol>
12
+
13
+ - (NSMutableURLRequest *)requestForSocketID : (NSString *)socketID channel : (PusherChannel *)channel ;
14
+
15
+ @end
16
+
17
+ @implementation AuthRequestBuilder
18
+
19
+ - (NSMutableURLRequest *)requestForSocketID : (NSString *)socketID channel : (PusherChannel *)channel {
20
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: [[NSURL alloc ] initWithString: @" http://localhost:9292/pusher/auth" ]];
21
+ NSString *dataStr = [NSString stringWithFormat: @" socket_id=%@ &channel_name=%@ " , socketID, [channel name ]];
22
+ NSData *data = [dataStr dataUsingEncoding: NSUTF8StringEncoding];
23
+ request.HTTPBody = data;
24
+ request.HTTPMethod = @" POST" ;
25
+ return request;
26
+ }
27
+
28
+ @end
29
+
11
30
@interface ViewController ()
12
31
13
32
@end
@@ -20,6 +39,10 @@ - (void)viewDidLoad {
20
39
OCAuthMethod *authMethod = [[OCAuthMethod alloc ] initWithSecret: @" YOUR_APP_SECRET" ];
21
40
PusherClientOptions *options = [[PusherClientOptions alloc ] initWithAuthMethod: authMethod];
22
41
42
+ // Use this if you want to try out your auth Endpoint
43
+ // OCAuthMethod *endpointAuthMethod = [[OCAuthMethod alloc] initWithAuthRequestBuilder:[[AuthRequestBuilder alloc] init]];
44
+ // PusherClientOptions *optionsWithEndpoint = [[PusherClientOptions alloc] initWithAuthMethod:endpointAuthMethod];
45
+
23
46
self.client = [[Pusher alloc ] initWithAppKey: @" YOUR_APP_KEY" options: options];
24
47
self.client .connection .delegate = self;
25
48
@@ -88,3 +111,4 @@ - (void)didReceiveMemoryWarning {
88
111
}
89
112
90
113
@end
114
+
Original file line number Diff line number Diff line change @@ -25,8 +25,14 @@ 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: " daef58559fdd0aba8b63 " ) )
29
- pusher = Pusher ( key: " 568d5a3851502158a022 " , options: pusherClientOptions)
28
+ let pusherClientOptions = PusherClientOptions ( authMethod: . inline( secret: " YOUR_APP_SECRET " ) )
29
+ pusher = Pusher ( key: " YOUR_APP_KEY " , options: pusherClientOptions)
30
+
31
+ // Use this if you want to try out your auth endpoint
32
+ // let optionsWithEndpoint = PusherClientOptions(
33
+ // authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder())
34
+ // )
35
+ // pusher = Pusher(key: "YOUR_APP_KEY", options: optionsWithEndpoint)
30
36
31
37
pusher. delegate = self
32
38
@@ -77,3 +83,11 @@ class ViewController: UIViewController, PusherDelegate {
77
83
}
78
84
}
79
85
86
+ class AuthRequestBuilder : AuthRequestBuilderProtocol {
87
+ func requestFor( socketID: String , channel: PusherChannel ) -> URLRequest ? {
88
+ var request = URLRequest ( url: URL ( string: " http://localhost:9292/pusher/auth " ) !)
89
+ request. httpMethod = " POST "
90
+ request. httpBody = " socket_id= \( socketID) &channel_name= \( channel. name) " . data ( using: String . Encoding. utf8)
91
+ return request
92
+ }
93
+ }
You can’t perform that action at this time.
0 commit comments