ios start using lightweight generics

This commit is contained in:
Andy Prock 2015-12-16 11:47:43 -08:00
parent f298b2a95d
commit defd529dc2
5 changed files with 25 additions and 20 deletions

29
.gitignore vendored
View File

@ -1,10 +1,9 @@
# OSX
#
.DS_Store
# Xcode # Xcode
# !**/*.xcodeproj
build/ !**/*.pbxproj
!**/*.xcworkspacedata
!**/*.xcsettings
!**/*.xcscheme
*.pbxuser *.pbxuser
!default.pbxuser !default.pbxuser
*.mode1v3 *.mode1v3
@ -22,13 +21,19 @@ DerivedData
*.xcuserstate *.xcuserstate
project.xcworkspace project.xcworkspace
# Android/IJ # Xcode, Gradle
# build/
# Android
.idea .idea
.gradle .gradle
local.properties local.properties
*.iml
# node.js # Node
# node_modules
node_modules/ *.log
npm-debug.log .nvm
# OS X
.DS_Store

View File

@ -21,7 +21,7 @@ NSString *const RCTUDPErrorDomain = @"RCTUDPErrorDomain";
NSString* _address; NSString* _address;
GCDAsyncUdpSocket *_udpSocket; GCDAsyncUdpSocket *_udpSocket;
id<SocketClientDelegate> _clientDelegate; id<SocketClientDelegate> _clientDelegate;
NSMutableDictionary* _pendingSends; NSMutableDictionary<NSNumber *, RCTResponseSenderBlock> *_pendingSends;
long tag; long tag;
} }

View File

@ -16,6 +16,6 @@
@interface UdpSockets : NSObject<SocketClientDelegate, RCTBridgeModule> @interface UdpSockets : NSObject<SocketClientDelegate, RCTBridgeModule>
+(NSMutableDictionary *)clients; +(NSMutableDictionary<NSNumber *, UdpSocketClient *> *)clients;
@end @end

View File

@ -44,7 +44,7 @@ RCT_EXPORT_METHOD(createSocket:(nonnull NSNumber*)cId withOptions:(NSDictionary*
{ {
// if (!UdpSockets._clients) UdpSockets._clients = [[NSMutableDictionary alloc] init]; // if (!UdpSockets._clients) UdpSockets._clients = [[NSMutableDictionary alloc] init];
NSMutableDictionary* _clients = [UdpSockets clients]; NSMutableDictionary<NSNumber *, UdpSocketClient *> *_clients = [UdpSockets clients];
if (!cId) { if (!cId) {
RCTLogError(@"%@.createSocket called with nil id parameter.", [self class]); RCTLogError(@"%@.createSocket called with nil id parameter.", [self class]);
return; return;
@ -126,8 +126,8 @@ RCT_EXPORT_METHOD(dropMembership:(nonnull NSNumber*)cId
- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port - (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port
{ {
NSMutableDictionary* _clients = [UdpSockets clients]; NSMutableDictionary<NSNumber *, UdpSocketClient *> *_clients = [UdpSockets clients];
NSString *clientID = [[_clients allKeysForObject:client] objectAtIndex:0]; NSNumber *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
NSString *base64String = [data base64EncodedStringWithOptions:0]; NSString *base64String = [data base64EncodedStringWithOptions:0];
[self.bridge.eventDispatcher sendDeviceEventWithName:[NSString stringWithFormat:@"udp-%@-data", clientID] [self.bridge.eventDispatcher sendDeviceEventWithName:[NSString stringWithFormat:@"udp-%@-data", clientID]
body:@{ body:@{
@ -140,7 +140,7 @@ RCT_EXPORT_METHOD(dropMembership:(nonnull NSNumber*)cId
+(UdpSocketClient*)findClient:(nonnull NSNumber*)cId callback:(RCTResponseSenderBlock)callback +(UdpSocketClient*)findClient:(nonnull NSNumber*)cId callback:(RCTResponseSenderBlock)callback
{ {
NSMutableDictionary* _clients = [UdpSockets clients]; NSMutableDictionary<NSNumber *, UdpSocketClient *> *_clients = [UdpSockets clients];
UdpSocketClient *client = [_clients objectForKey:cId]; UdpSocketClient *client = [_clients objectForKey:cId];
if (!client) { if (!client) {
if (!callback) { if (!callback) {
@ -159,7 +159,7 @@ RCT_EXPORT_METHOD(dropMembership:(nonnull NSNumber*)cId
+(void) closeClient:(nonnull NSNumber*)cId +(void) closeClient:(nonnull NSNumber*)cId
callback:(RCTResponseSenderBlock)callback callback:(RCTResponseSenderBlock)callback
{ {
NSMutableDictionary* _clients = [UdpSockets clients]; NSMutableDictionary<NSNumber *, UdpSocketClient *> *_clients = [UdpSockets clients];
UdpSocketClient* client = [UdpSockets findClient:cId callback:callback]; UdpSocketClient* client = [UdpSockets findClient:cId callback:callback];
if (!client) return; if (!client) return;
@ -170,7 +170,7 @@ RCT_EXPORT_METHOD(dropMembership:(nonnull NSNumber*)cId
} }
+(void) closeAllSockets { +(void) closeAllSockets {
NSMutableDictionary* _clients = [UdpSockets clients]; NSMutableDictionary<NSNumber *, UdpSocketClient *> *_clients = [UdpSockets clients];
for (NSNumber* cId in _clients) { for (NSNumber* cId in _clients) {
[UdpSockets closeClient:cId callback:nil]; [UdpSockets closeClient:cId callback:nil];
} }