mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers Differential Revision: D2651920 fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
This commit is contained in:
committed by
facebook-github-bot-4
parent
5a34a097f2
commit
fa0b45c58b
@@ -506,7 +506,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
|
||||
|
||||
if (_secure) {
|
||||
NSMutableDictionary *SSLOptions = [NSMutableDictionary new];
|
||||
NSMutableDictionary<NSString *, id> *SSLOptions = [NSMutableDictionary new];
|
||||
|
||||
[_outputStream setProperty:(__bridge id)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(__bridge id)kCFStreamPropertySocketSecurityLevel];
|
||||
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
|
||||
#import "RCTConvert.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTSparseArray.h"
|
||||
#import "RCTUtils.h"
|
||||
#import "RCTSRWebSocket.h"
|
||||
|
||||
typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply);
|
||||
typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary<NSString *, id> *reply);
|
||||
|
||||
@interface RCTWebSocketExecutor () <RCTSRWebSocketDelegate>
|
||||
|
||||
@@ -29,9 +28,9 @@ typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply);
|
||||
{
|
||||
RCTSRWebSocket *_socket;
|
||||
dispatch_queue_t _jsQueue;
|
||||
RCTSparseArray *_callbacks;
|
||||
NSMutableDictionary<NSNumber *, RCTWSMessageCallback> *_callbacks;
|
||||
dispatch_semaphore_t _socketOpenSemaphore;
|
||||
NSMutableDictionary *_injectedObjects;
|
||||
NSMutableDictionary<NSString *, NSString *> *_injectedObjects;
|
||||
NSURL *_url;
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ RCT_EXPORT_MODULE()
|
||||
_jsQueue = dispatch_queue_create("com.facebook.React.WebSocketExecutor", DISPATCH_QUEUE_SERIAL);
|
||||
_socket = [[RCTSRWebSocket alloc] initWithURL:_url];
|
||||
_socket.delegate = self;
|
||||
_callbacks = [RCTSparseArray new];
|
||||
_callbacks = [NSMutableDictionary new];
|
||||
_injectedObjects = [NSMutableDictionary new];
|
||||
[_socket setDelegateDispatchQueue:_jsQueue];
|
||||
|
||||
@@ -101,7 +100,7 @@ RCT_EXPORT_MODULE()
|
||||
{
|
||||
__block NSError *initError;
|
||||
dispatch_semaphore_t s = dispatch_semaphore_create(0);
|
||||
[self sendMessage:@{@"method": @"prepareJSRuntime"} waitForReply:^(NSError *error, NSDictionary *reply) {
|
||||
[self sendMessage:@{@"method": @"prepareJSRuntime"} waitForReply:^(NSError *error, NSDictionary<NSString *, id> *reply) {
|
||||
initError = error;
|
||||
dispatch_semaphore_signal(s);
|
||||
}];
|
||||
@@ -112,7 +111,7 @@ RCT_EXPORT_MODULE()
|
||||
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSDictionary *reply = RCTJSONParse(message, &error);
|
||||
NSDictionary<NSString *, id> *reply = RCTJSONParse(message, &error);
|
||||
NSNumber *messageID = reply[@"replyID"];
|
||||
RCTWSMessageCallback callback = _callbacks[messageID];
|
||||
if (callback) {
|
||||
@@ -130,7 +129,7 @@ RCT_EXPORT_MODULE()
|
||||
RCTLogError(@"WebSocket connection failed with error %@", error);
|
||||
}
|
||||
|
||||
- (void)sendMessage:(NSDictionary *)message waitForReply:(RCTWSMessageCallback)callback
|
||||
- (void)sendMessage:(NSDictionary<NSString *, id> *)message waitForReply:(RCTWSMessageCallback)callback
|
||||
{
|
||||
static NSUInteger lastID = 10000;
|
||||
|
||||
@@ -145,7 +144,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
NSNumber *expectedID = @(lastID++);
|
||||
_callbacks[expectedID] = [callback copy];
|
||||
NSMutableDictionary *messageWithID = [message mutableCopy];
|
||||
NSMutableDictionary<NSString *, id> *messageWithID = [message mutableCopy];
|
||||
messageWithID[@"id"] = expectedID;
|
||||
[_socket send:RCTJSONStringify(messageWithID, NULL)];
|
||||
});
|
||||
@@ -153,12 +152,12 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
- (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)URL onComplete:(RCTJavaScriptCompleteBlock)onComplete
|
||||
{
|
||||
NSDictionary *message = @{
|
||||
NSDictionary<NSString *, id> *message = @{
|
||||
@"method": @"executeApplicationScript",
|
||||
@"url": RCTNullIfNil(URL.absoluteString),
|
||||
@"inject": _injectedObjects,
|
||||
};
|
||||
[self sendMessage:message waitForReply:^(NSError *error, NSDictionary *reply) {
|
||||
[self sendMessage:message waitForReply:^(NSError *error, NSDictionary<NSString *, id> *reply) {
|
||||
onComplete(error);
|
||||
}];
|
||||
}
|
||||
@@ -166,13 +165,13 @@ RCT_EXPORT_MODULE()
|
||||
- (void)executeJSCall:(NSString *)name method:(NSString *)method arguments:(NSArray *)arguments callback:(RCTJavaScriptCallback)onComplete
|
||||
{
|
||||
RCTAssert(onComplete != nil, @"callback was missing for exec JS call");
|
||||
NSDictionary *message = @{
|
||||
NSDictionary<NSString *, id> *message = @{
|
||||
@"method": @"executeJSCall",
|
||||
@"moduleName": name,
|
||||
@"moduleMethod": method,
|
||||
@"arguments": arguments
|
||||
};
|
||||
[self sendMessage:message waitForReply:^(NSError *socketError, NSDictionary *reply) {
|
||||
[self sendMessage:message waitForReply:^(NSError *socketError, NSDictionary<NSString *, id> *reply) {
|
||||
if (socketError) {
|
||||
onComplete(nil, socketError);
|
||||
return;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTSRWebSocket.h"
|
||||
#import "RCTSparseArray.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
@implementation RCTSRWebSocket (React)
|
||||
@@ -35,7 +34,7 @@
|
||||
|
||||
@implementation RCTWebSocketModule
|
||||
{
|
||||
RCTSparseArray *_sockets;
|
||||
NSMutableDictionary<NSNumber *, RCTSRWebSocket *> *_sockets;
|
||||
}
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
@@ -45,14 +44,14 @@ RCT_EXPORT_MODULE()
|
||||
- (instancetype)init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_sockets = [RCTSparseArray new];
|
||||
_sockets = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
for (RCTSRWebSocket *socket in _sockets.allObjects) {
|
||||
for (RCTSRWebSocket *socket in _sockets.allValues) {
|
||||
socket.delegate = nil;
|
||||
[socket close];
|
||||
}
|
||||
@@ -75,7 +74,7 @@ RCT_EXPORT_METHOD(send:(NSString *)message socketID:(nonnull NSNumber *)socketID
|
||||
RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID)
|
||||
{
|
||||
[_sockets[socketID] close];
|
||||
_sockets[socketID] = nil;
|
||||
[_sockets removeObjectForKey:socketID];
|
||||
}
|
||||
|
||||
#pragma mark - RCTSRWebSocketDelegate methods
|
||||
|
||||
Reference in New Issue
Block a user