Skip to content

Commit 0b68d69

Browse files
committed
add removeClient
1 parent 3ce7ed4 commit 0b68d69

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

ios/RCTMqtt/RCTMqtt.m

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,42 @@ - (void)appDidBecomeActive {
8585
resolve([NSNumber numberWithInt:clientRef]);
8686

8787
}
88-
RCT_EXPORT_METHOD(connect:(int) clientRef) {
88+
89+
RCT_EXPORT_METHOD(removeClient:(int) clientRef
90+
resolver:(RCTPromiseResolveBlock)resolve
91+
rejecter:(RCTPromiseRejectBlock)reject) {
8992

90-
[[[self clients] objectForKey:[NSNumber numberWithInt:clientRef]] connect];
93+
[[self clients] removeObjectForKey:[NSNumber numberWithInt:clientRef]];
94+
resolve([NSNumber numberWithInt:clientRef]);
9195

9296
}
9397

94-
95-
RCT_EXPORT_METHOD(disconnect:(int) clientRef) {
96-
[[[self clients] objectForKey:[NSNumber numberWithInt:clientRef]] disconnect];
98+
RCT_EXPORT_METHOD(connect:(nonnull NSNumber *) clientRef) {
99+
100+
[[[self clients] objectForKey:clientRef] connect];
101+
97102
}
98103

99-
RCT_EXPORT_METHOD(subscribe:(int) clientRef topic:(NSString *)topic qos:(int)qos) {
100-
[[[self clients] objectForKey:[NSNumber numberWithInt:clientRef]] subscribe:topic qos:[NSNumber numberWithInt:qos]];
101-
104+
105+
RCT_EXPORT_METHOD(disconnect:(nonnull NSNumber *) clientRef) {
106+
[[[self clients] objectForKey:clientRef] disconnect];
102107
}
103108

104-
RCT_EXPORT_METHOD(unsubscribe:(int) clientRef topic:(NSString *)topic) {
105-
[[[self clients] objectForKey:[NSNumber numberWithInt:clientRef]] unsubscribe:topic];
109+
RCT_EXPORT_METHOD(subscribe:(nonnull NSNumber *) clientRef topic:(NSString *)topic qos:(nonnull NSNumber *)qos) {
110+
[[[self clients] objectForKey:clientRef] subscribe:topic qos:qos]];
106111

107112
}
108113

109-
RCT_EXPORT_METHOD(publish:(int) clientRef topic:(NSString *)topic data:(NSString*)data qos:(int)qos retain:(int)retain) {
110-
[[[self clients] objectForKey:[NSNumber numberWithInt:clientRef]] publish:topic
111-
data:[data dataUsingEncoding:NSUTF8StringEncoding]
112-
qos:[NSNumber numberWithInt:qos]
113-
retain:(BOOL)retain];
114+
RCT_EXPORT_METHOD(publish:(nonnull NSNumber *) clientRef topic:(NSString *)topic data:(NSString*)data qos:(nonnull NSNumber *)qos retain:(BOOL)retain) {
115+
[[[self clients] objectForKey:clientRef] publish:topic
116+
data:[data dataUsingEncoding:NSUTF8StringEncoding]
117+
qos:qos
118+
retain:retain];
119+
120+
}
114121

122+
RCT_EXPORT_METHOD(unsubscribe:(nonnull NSNumber *) clientRef topic:(NSString *)topic) {
123+
[[[self clients] objectForKey:clientRef] unsubscribe:topic];
115124
}
116125

117126
- (void)dealloc

0 commit comments

Comments
 (0)