feat: 1. ios debugger remote connected
TODO: fix arg type
This commit is contained in:
parent
70a6c9193a
commit
e5106a25ba
@ -51,7 +51,7 @@ + (instancetype)instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source {
|
- (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source {
|
||||||
context.contextId = [NSString stringWithFormat:@"%ld", (long) self.counter++];
|
context.contextId = [NSString stringWithFormat:@"%ld", (long) ++self.counter];
|
||||||
[context.driver createContext:context.contextId script:script source:source];
|
[context.driver createContext:context.contextId script:script source:source];
|
||||||
dispatch_sync(self.mapQueue, ^() {
|
dispatch_sync(self.mapQueue, ^() {
|
||||||
NSValue *value = [NSValue valueWithNonretainedObject:context];
|
NSValue *value = [NSValue valueWithNonretainedObject:context];
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#import "DoricJSRemoteExecutor.h"
|
#import "DoricJSRemoteExecutor.h"
|
||||||
#import <SocketRocket/SRWebSocket.h>
|
#import <SocketRocket/SRWebSocket.h>
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
|
#import "DoricJSRemoteArgType.h"
|
||||||
|
#import "NSString+JsonString.h"
|
||||||
|
|
||||||
static NSString * const kUrlStr = @"ws://192.168.24.240:2080";
|
static NSString * const kUrlStr = @"ws://192.168.24.240:2080";
|
||||||
|
|
||||||
@ -121,19 +123,18 @@ - (NSString *)loadJSScript:(NSString *)script source:(NSString *)source {
|
|||||||
- (void)injectGlobalJSObject:(NSString *)name obj:(id)obj {
|
- (void)injectGlobalJSObject:(NSString *)name obj:(id)obj {
|
||||||
if ([obj isKindOfClass:NSClassFromString(@"NSBlock")]) {
|
if ([obj isKindOfClass:NSClassFromString(@"NSBlock")]) {
|
||||||
self.blockMDic[name] = obj;
|
self.blockMDic[name] = obj;
|
||||||
} else {
|
|
||||||
NSDictionary *jsonDic = @{
|
|
||||||
@"cmd": @"injectGlobalJSFunction",
|
|
||||||
@"name": name
|
|
||||||
};
|
|
||||||
NSError *err;
|
|
||||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:0 error:&err];
|
|
||||||
if (err) {
|
|
||||||
DoricLog(@"debugger ", NSStringFromSelector(_cmd), @" failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
[self.srWebSocket send:jsonData];
|
|
||||||
}
|
}
|
||||||
|
NSDictionary *jsonDic = @{
|
||||||
|
@"cmd": @"injectGlobalJSFunction",
|
||||||
|
@"name": name
|
||||||
|
};
|
||||||
|
|
||||||
|
NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic];
|
||||||
|
if (!jsonStr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.srWebSocket send:jsonStr];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(NSArray *)args {
|
- (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(NSArray *)args {
|
||||||
@ -141,27 +142,27 @@ - (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(
|
|||||||
NSMutableArray *argsMArr = [NSMutableArray new];
|
NSMutableArray *argsMArr = [NSMutableArray new];
|
||||||
for (id arg in args) {
|
for (id arg in args) {
|
||||||
NSDictionary *dic = @{
|
NSDictionary *dic = @{
|
||||||
@"type": [arg class],
|
@"type": @(DoricargTypeWithArg(arg)),
|
||||||
@"value": arg
|
@"value": arg
|
||||||
};
|
};
|
||||||
[argsMArr addObject:dic];
|
[argsMArr addObject:dic];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSArray *argsArr = [argsMArr copy];
|
||||||
|
|
||||||
NSDictionary *jsonDic = @{
|
NSDictionary *jsonDic = @{
|
||||||
@"cmd": @"invokeMethod",
|
@"cmd": @"invokeMethod",
|
||||||
@"obj": objName,
|
@"objectName": objName,
|
||||||
@"functionName": funcName,
|
@"functionName": funcName,
|
||||||
@"javaValues": argsMArr
|
@"javaValues": argsArr
|
||||||
};
|
};
|
||||||
|
|
||||||
NSError * err;
|
NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic];
|
||||||
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:0 error:&err];
|
if (!jsonStr) {
|
||||||
if (err) {
|
|
||||||
DoricLog(@"debugger ", NSStringFromSelector(_cmd), @" failed");
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.srWebSocket send:jsonData];
|
[self.srWebSocket send:jsonStr];
|
||||||
DC_LOCK(self.semaphore);
|
DC_LOCK(self.semaphore);
|
||||||
|
|
||||||
return self.temp;
|
return self.temp;
|
||||||
|
18
iOS/Pod/Classes/Util/Category/NSString+JsonString.h
Normal file
18
iOS/Pod/Classes/Util/Category/NSString+JsonString.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// NSString+JsonString.h
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by Insomnia on 2019/11/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface NSString (JsonString)
|
||||||
|
+ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic;
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
23
iOS/Pod/Classes/Util/Category/NSString+JsonString.m
Normal file
23
iOS/Pod/Classes/Util/Category/NSString+JsonString.m
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// NSString+JsonString.m
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by Insomnia on 2019/11/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "NSString+JsonString.h"
|
||||||
|
#import "DoricUtil.h"
|
||||||
|
|
||||||
|
@implementation NSString (JsonString)
|
||||||
|
+ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic {
|
||||||
|
NSError *err;
|
||||||
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&err];
|
||||||
|
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
DoricLog(NSStringFromSelector(_cmd), @"Convert dictionary to json string failed.");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
return jsonStr;
|
||||||
|
}
|
||||||
|
@end
|
23
iOS/Pod/Classes/Util/DoricJSRemoteArgType.h
Normal file
23
iOS/Pod/Classes/Util/DoricJSRemoteArgType.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// DoricJSRemoteArgType.h
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by Insomnia on 2019/11/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) {
|
||||||
|
DoricJSRemoteArgTypeNil = 0,
|
||||||
|
DoricJSRemoteArgTypeInteger,
|
||||||
|
DoricJSRemoteArgTypeBool,
|
||||||
|
DoricJSRemoteArgTypeString,
|
||||||
|
DoricJSRemoteArgTypeObject,
|
||||||
|
DoricJSRemoteArgTypeArray,
|
||||||
|
};
|
||||||
|
|
||||||
|
DoricJSRemoteArgType DoricargTypeWithArg(id arg);
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
12
iOS/Pod/Classes/Util/DoricJSRemoteArgType.m
Normal file
12
iOS/Pod/Classes/Util/DoricJSRemoteArgType.m
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// DoricJSRemoteArgType.m
|
||||||
|
// Doric
|
||||||
|
//
|
||||||
|
// Created by Insomnia on 2019/11/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricJSRemoteArgType.h"
|
||||||
|
DoricJSRemoteArgType DoricargTypeWithArg(id arg) {
|
||||||
|
// TODO: 类型缺失
|
||||||
|
return DoricJSRemoteArgTypeString;
|
||||||
|
}
|
Reference in New Issue
Block a user