Skip to content

Commit

Permalink
inject wrapper agents into push channel
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-forooghian committed Feb 13, 2025
1 parent 35a766a commit fa17140
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
53 changes: 27 additions & 26 deletions Source/ARTPushChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@ - (instancetype)initWithInternal:(ARTPushChannelInternal *)internal queuedDeallo
}

- (void)subscribeDevice {
[_internal subscribeDevice];
[_internal subscribeDeviceWithWrapperSDKAgents:nil];
}

- (void)subscribeDevice:(ARTCallback)callback {
[_internal subscribeDevice:callback];
[_internal subscribeDeviceWithWrapperSDKAgents:nil completion:callback];
}

- (void)subscribeClient {
[_internal subscribeClient];
[_internal subscribeClientWithWrapperSDKAgents:nil];
}

- (void)subscribeClient:(ARTCallback)callback {
[_internal subscribeClient:callback];
[_internal subscribeClientWithWrapperSDKAgents:nil completion:callback];
}

- (void)unsubscribeDevice {
[_internal unsubscribeDevice];
[_internal unsubscribeDeviceWithWrapperSDKAgents:nil];
}

- (void)unsubscribeDevice:(ARTCallback)callback {
[_internal unsubscribeDevice:callback];
[_internal unsubscribeDeviceWithWrapperSDKAgents:nil completion:callback];
}

- (void)unsubscribeClient {
[_internal unsubscribeClient];
[_internal unsubscribeClientWithWrapperSDKAgents:nil];
}

- (void)unsubscribeClient:(ARTCallback)callback {
[_internal unsubscribeClient:callback];
[_internal unsubscribeClientWithWrapperSDKAgents:nil completion:callback];
}

- (BOOL)listSubscriptions:(NSStringDictionary *)params
callback:(ARTPaginatedPushChannelCallback)callback
error:(NSError *_Nullable *_Nullable)errorPtr {
return [_internal listSubscriptions:params callback:callback error:errorPtr];
return [_internal listSubscriptions:params wrapperSDKAgents:nil callback:callback error:errorPtr];
}

@end
Expand Down Expand Up @@ -86,23 +86,23 @@ - (instancetype)init:(ARTRestInternal *)rest withChannel:(ARTChannel *)channel l
return self;
}

- (void)subscribeDevice {
[self subscribeDevice:nil];
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self subscribeDeviceWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)unsubscribeDevice {
[self unsubscribeDevice:nil];
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self unsubscribeDeviceWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)subscribeClient {
[self subscribeClient:nil];
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self subscribeClientWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)unsubscribeClient {
[self unsubscribeClient:nil];
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self unsubscribeClientWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)subscribeDevice:(ARTCallback)callback {
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -129,7 +129,7 @@ - (void)subscribeDevice:(ARTCallback)callback {
[request setDeviceAuthentication:deviceId localDevice:device];

ARTLogDebug(self->_logger, @"subscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: subscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
}
Expand All @@ -138,7 +138,7 @@ - (void)subscribeDevice:(ARTCallback)callback {
});
}

- (void)subscribeClient:(ARTCallback)callback {
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -163,7 +163,7 @@ - (void)subscribeClient:(ARTCallback)callback {
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

ARTLogDebug(self->_logger, @"subscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: subscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
}
Expand All @@ -172,7 +172,7 @@ - (void)subscribeClient:(ARTCallback)callback {
});
}

- (void)unsubscribeDevice:(ARTCallback)callback {
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand Down Expand Up @@ -200,7 +200,7 @@ - (void)unsubscribeDevice:(ARTCallback)callback {
[request setDeviceAuthentication:deviceId localDevice:device];

ARTLogDebug(self->_logger, @"unsubscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: unsubscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
}
Expand All @@ -209,7 +209,7 @@ - (void)unsubscribeDevice:(ARTCallback)callback {
});
}

- (void)unsubscribeClient:(ARTCallback)callback {
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -235,7 +235,7 @@ - (void)unsubscribeClient:(ARTCallback)callback {
request.HTTPMethod = @"DELETE";

ARTLogDebug(self->_logger, @"unsubscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: unsubscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
}
Expand All @@ -245,6 +245,7 @@ - (void)unsubscribeClient:(ARTCallback)callback {
}

- (BOOL)listSubscriptions:(NSStringDictionary *)params
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
callback:(ARTPaginatedPushChannelCallback)callback
error:(NSError * __autoreleasing *)errorPtr {
if (callback) {
Expand Down Expand Up @@ -290,7 +291,7 @@ - (BOOL)listSubscriptions:(NSStringDictionary *)params
return [self->_rest.encoders[response.MIMEType] decodePushChannelSubscriptions:data error:error];
};

[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:nil logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
ret = YES;
});
return ret;
Expand Down
22 changes: 14 additions & 8 deletions Source/ARTWrapperSDKProxyPushChannel.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "ARTWrapperSDKProxyPushChannel+Private.h"
#import "ARTPushChannel+Private.h"
#import "ARTWrapperSDKProxyOptions.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -27,35 +29,39 @@ - (BOOL)listSubscriptions:(nonnull NSStringDictionary *)params callback:(nonnull
}

- (void)subscribeClient {
[self.underlyingPushChannel subscribeClient];
[self.underlyingPushChannel.internal subscribeClientWithWrapperSDKAgents:self.proxyOptions.agents];
}

- (void)subscribeClient:(nullable ARTCallback)callback {
[self.underlyingPushChannel subscribeClient:callback];
[self.underlyingPushChannel.internal subscribeClientWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

- (void)subscribeDevice {
[self.underlyingPushChannel subscribeDevice];
[self.underlyingPushChannel.internal subscribeDeviceWithWrapperSDKAgents:self.proxyOptions.agents];
}

- (void)subscribeDevice:(nullable ARTCallback)callback {
[self.underlyingPushChannel subscribeDevice:callback];
[self.underlyingPushChannel.internal subscribeDeviceWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

- (void)unsubscribeClient {
[self.underlyingPushChannel unsubscribeClient];
[self.underlyingPushChannel.internal unsubscribeClientWithWrapperSDKAgents:self.proxyOptions.agents];
}

- (void)unsubscribeClient:(nullable ARTCallback)callback {
[self.underlyingPushChannel unsubscribeClient:callback];
[self.underlyingPushChannel.internal unsubscribeClientWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

- (void)unsubscribeDevice {
[self.underlyingPushChannel unsubscribeDevice];
[self.underlyingPushChannel.internal unsubscribeDeviceWithWrapperSDKAgents:self.proxyOptions.agents];
}

- (void)unsubscribeDevice:(nullable ARTCallback)callback {
[self.underlyingPushChannel unsubscribeDevice:callback];
[self.underlyingPushChannel.internal unsubscribeDeviceWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

@end
21 changes: 13 additions & 8 deletions Source/PrivateHeaders/Ably/ARTPushChannel+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)init:(ARTRestInternal *)rest withChannel:(ARTChannel *)channel logger:(ARTInternalLog *)logger;

- (void)subscribeDevice;
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents;

- (void)subscribeDevice:(nullable ARTCallback)callback;
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(nullable ARTCallback)callback;

- (void)subscribeClient;
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents;

- (void)subscribeClient:(nullable ARTCallback)callback;
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(nullable ARTCallback)callback;

- (void)unsubscribeDevice;
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents;

- (void)unsubscribeDevice:(nullable ARTCallback)callback;
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(nullable ARTCallback)callback;

- (void)unsubscribeClient;
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents;

- (void)unsubscribeClient:(nullable ARTCallback)callback;
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(nullable ARTCallback)callback;

- (BOOL)listSubscriptions:(NSStringDictionary *)params
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
callback:(ARTPaginatedPushChannelCallback)callback
error:(NSError *_Nullable *_Nullable)errorPtr;

Expand Down

0 comments on commit fa17140

Please sign in to comment.