diff --git a/Source/ARTRealtimeWrapperSDKProxy.m b/Source/ARTRealtimeWrapperSDKProxy.m index 958e82945..f85f8b041 100644 --- a/Source/ARTRealtimeWrapperSDKProxy.m +++ b/Source/ARTRealtimeWrapperSDKProxy.m @@ -10,6 +10,33 @@ @interface ARTRealtimeWrapperSDKProxy () @end +@interface ARTRealtimeWrapperSDKChannelsProxy () + +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithChannels:(ARTRealtimeChannels *)channels + options:(ARTWrapperProxyOptions *)options NS_DESIGNATED_INITIALIZER; + +// TODO split into files; this is private + +@property (nonatomic, readonly) ARTRealtimeChannels *channels; +@property (nonatomic, readonly) ARTWrapperProxyOptions *options; + +@end + +@interface ARTRealtimeWrapperSDKChannelProxy () + +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithChannel:(ARTRealtimeChannel *)channel + options:(ARTWrapperProxyOptions *)options NS_DESIGNATED_INITIALIZER; + +// TODO split into files; this is private + +@property (nonatomic, readonly) ARTRealtimeChannel *channel; +// TODO consider making this naming consistent (in this class it's to avoid clash with property called `options`) +@property (nonatomic, readonly) ARTWrapperProxyOptions *proxyOptions; + +@end + NS_ASSUME_NONNULL_END @implementation ARTRealtimeWrapperSDKProxy @@ -56,12 +83,6 @@ - (void)connect { [self.realtime connect]; } -- (nonnull id)createWrapperSDKProxyWithOptions:(nonnull ARTWrapperProxyOptions *)options { - @throw [NSException exceptionWithName:NSInvalidArgumentException - reason:@"You can not call -createWrapperProxyWithOptions: on a proxy object." - userInfo: nil]; -} - - (void)ping:(nonnull ARTCallback)cb { [self.realtime ping:cb]; } @@ -97,3 +118,205 @@ - (void)time:(nonnull ARTDateTimeCallback)callback { } @end + +@implementation ARTRealtimeWrapperSDKChannelsProxy + +- (instancetype)initWithChannels:(ARTRealtimeChannels *)channels options:(ARTWrapperProxyOptions *)options { + if (self = [super init]) { + _channels = channels; + _options = options; + } + + return self; +} + +- (BOOL)exists:(nonnull NSString *)name { + return [self.channels exists:name]; +} + +- (void)release:(nonnull NSString *)name { + [self.channels release:name]; +} + +- (void)release:(nonnull NSString *)name callback:(nullable ARTCallback)errorInfo { + [self.channels release:name callback:errorInfo]; +} + +- (ARTRealtimeWrapperSDKChannelProxy *)get:(NSString *)name { + ARTRealtimeChannel *channel = [self.channels get:name]; + // TODO reuse existing instance + return [[ARTRealtimeWrapperSDKChannelProxy alloc] initWithChannel:channel + options:self.options]; +} + +- (ARTRealtimeWrapperSDKChannelProxy *)get:(NSString *)name options:(ARTRealtimeChannelOptions *)options { + ARTRealtimeChannel *channel = [self.channels get:name + options:options]; + // TODO reuse existing instance + return [[ARTRealtimeWrapperSDKChannelProxy alloc] initWithChannel:channel + options:self.options]; +} + +@end + +@implementation ARTRealtimeWrapperSDKChannelProxy + +- (instancetype)initWithChannel:(ARTRealtimeChannel *)channel options:(ARTWrapperProxyOptions *)options { + if (self = [super init]) { + _channel = channel; + _proxyOptions = options; + } + + return self; +} + +- (ARTErrorInfo *)errorReason { + return self.channel.errorReason; +} + +- (NSString *)name { + return self.channel.name; +} + +- (ARTRealtimeChannelOptions *)getOptions { + return self.channel.options; +} + +- (id)presence { + return self.channel.presence; +} + +- (ARTChannelProperties *)properties { + return self.channel.properties; +} + +- (ARTRealtimeChannelState)state { + return self.channel.state; + +} + +- (void)history:(nonnull ARTPaginatedMessagesCallback)callback { + [self.channel history:callback]; +} + +- (void)publish:(nonnull NSArray *)messages { + [self.channel publish:messages]; +} + +- (void)publish:(nonnull NSArray *)messages callback:(nullable ARTCallback)callback { + [self.channel publish:messages callback:callback]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data { + [self.channel publish:name data:data]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data callback:(nullable ARTCallback)callback { + [self.channel publish:name data:data callback:callback]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data clientId:(nonnull NSString *)clientId { + [self.channel publish:name data:data clientId:clientId]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data clientId:(nonnull NSString *)clientId callback:(nullable ARTCallback)callback { + [self.channel publish:name data:data clientId:clientId]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data clientId:(nonnull NSString *)clientId extras:(nullable id)extras { + [self.channel publish:name data:data clientId:clientId extras:extras]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data clientId:(nonnull NSString *)clientId extras:(nullable id)extras callback:(nullable ARTCallback)callback { + [self.channel publish:name data:data clientId:clientId extras:extras callback:callback]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data extras:(nullable id)extras { + [self.channel publish:name data:data extras:extras]; +} + +- (void)publish:(nullable NSString *)name data:(nullable id)data extras:(nullable id)extras callback:(nullable ARTCallback)callback { + [self.channel publish:name data:data extras:extras callback:callback]; +} + +- (void)attach { + [self.channel attach]; +} + +- (void)attach:(nullable ARTCallback)callback { + [self.channel attach:callback]; +} + +- (void)detach { + [self.channel detach]; +} + +- (void)detach:(nullable ARTCallback)callback { + [self.channel detach:callback]; +} + +- (BOOL)history:(ARTRealtimeHistoryQuery * _Nullable)query callback:(nonnull ARTPaginatedMessagesCallback)callback error:(NSError * _Nullable __autoreleasing * _Nullable)errorPtr { + return [self.channel history:query callback:callback error:errorPtr]; +} + +- (void)off { + [self.channel off]; +} + +- (void)off:(nonnull ARTEventListener *)listener { + [self.channel off:listener]; +} + +- (void)off:(ARTChannelEvent)event listener:(nonnull ARTEventListener *)listener { + [self.channel off:event listener:listener]; +} + +- (nonnull ARTEventListener *)on:(nonnull void (^)(ARTChannelStateChange * _Nonnull))cb { + return [self.channel on:cb]; +} + +- (nonnull ARTEventListener *)on:(ARTChannelEvent)event callback:(nonnull void (^)(ARTChannelStateChange * _Nonnull))cb { + return [self.channel on:event callback:cb]; +} + +- (nonnull ARTEventListener *)once:(nonnull void (^)(ARTChannelStateChange * _Nonnull))cb { + return [self.channel once:cb]; +} + +- (nonnull ARTEventListener *)once:(ARTChannelEvent)event callback:(nonnull void (^)(ARTChannelStateChange * _Nonnull))cb { + return [self.channel once:event callback:cb]; +} + +- (void)setOptions:(ARTRealtimeChannelOptions * _Nullable)options callback:(nullable ARTCallback)callback { + [self.channel setOptions:options callback:callback]; +} + +- (ARTEventListener * _Nullable)subscribe:(nonnull ARTMessageCallback)callback { + return [self.channel subscribe:callback]; +} + +- (ARTEventListener * _Nullable)subscribe:(nonnull NSString *)name callback:(nonnull ARTMessageCallback)callback { + return [self.channel subscribe:name callback:callback]; +} + +- (ARTEventListener * _Nullable)subscribe:(nonnull NSString *)name onAttach:(nullable ARTCallback)onAttach callback:(nonnull ARTMessageCallback)callback { + return [self.channel subscribe:name onAttach:onAttach callback:callback]; +} + +- (ARTEventListener * _Nullable)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(nonnull ARTMessageCallback)callback { + return [self.channel subscribeWithAttachCallback:onAttach callback:callback]; +} + +- (void)unsubscribe { + [self.channel unsubscribe]; +} + +- (void)unsubscribe:(ARTEventListener * _Nullable)listener { + [self.channel unsubscribe:listener]; +} + +- (void)unsubscribe:(nonnull NSString *)name listener:(ARTEventListener * _Nullable)listener { + [self.channel unsubscribe:name listener:listener]; +} + +@end diff --git a/Source/include/Ably/ARTRealtimeWrapperSDKProxy.h b/Source/include/Ably/ARTRealtimeWrapperSDKProxy.h index 6691a1a81..3eb748612 100644 --- a/Source/include/Ably/ARTRealtimeWrapperSDKProxy.h +++ b/Source/include/Ably/ARTRealtimeWrapperSDKProxy.h @@ -3,10 +3,12 @@ @class ARTWrapperProxyOptions; @class ARTConnection; -@class ARTRealtimeChannels; @class ARTPush; @class ARTAuth; +@class ARTRealtimeWrapperSDKChannelsProxy; +@class ARTRealtimeWrapperSDKChannelProxy; + // TODO exclude from docs NS_ASSUME_NONNULL_BEGIN @@ -15,10 +17,27 @@ NS_SWIFT_SENDABLE @interface ARTRealtimeWrapperSDKProxy : NSObject @property (readonly) ARTConnection *connection; -@property (readonly) ARTRealtimeChannels *channels; +@property (readonly) ARTRealtimeWrapperSDKChannelsProxy *channels; @property (readonly) ARTPush *push; @property (readonly) ARTAuth *auth; @end +NS_SWIFT_SENDABLE +@interface ARTRealtimeWrapperSDKChannelsProxy : NSObject + +- (ARTRealtimeWrapperSDKChannelProxy *)get:(NSString *)name; +- (ARTRealtimeWrapperSDKChannelProxy *)get:(NSString *)name options:(ARTRealtimeChannelOptions *)options; + +@end + +NS_SWIFT_SENDABLE +@interface ARTRealtimeWrapperSDKChannelProxy : NSObject + +#if TARGET_OS_IPHONE +@property (readonly) ARTPushChannel *push; +#endif + +@end + NS_ASSUME_NONNULL_END