add doric dev vc

This commit is contained in:
王劲鹏 2020-02-26 14:51:02 +08:00 committed by osborn
parent 3766c603ba
commit f9f48d9c8a
10 changed files with 135 additions and 11 deletions

View File

@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)connectDevKit:(NSString *)url;
- (void)sendDevCommand:(NSString *)command;
- (void)disconnectDevKit;
@end

View File

@ -51,6 +51,10 @@ - (void)connectDevKit:(NSString *)url {
self.wsclient = [[DoricWSClient alloc] initWithUrl:url];
}
- (void)sendDevCommand:(NSString *)command {
[self.wsclient send:command];
}
- (void)disconnectDevKit {
if (self.wsclient) {
[self.wsclient close];

View File

@ -0,0 +1,29 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// DoricDevViewController.h
// Doric
//
// Created by jingpeng.wang on 2020/2/26.
//
#import <UIKit/UIKit.h>
@interface DoricDevViewController : UIViewController
@end

View File

@ -0,0 +1,81 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// DoricDevViewController.m
// Doric
//
// Created by jingpeng.wang on 2020/2/26.
//
#import <DoricCore/Doric.h>
#import <DoricCore/DoricContextManager.h>
#import "DoricDev.h"
#import "DoricDevViewController.h"
#import "DoricJSRemoteExecutor.h"
#import "QRScanViewController.h"
@interface DoricDevViewController () <UITableViewDelegate, UITableViewDataSource>
@end
@implementation DoricDevViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Doric Devkit";
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
it.width = self.view.width;
it.height = self.view.height;
it.left = it.top = 0;
it.dataSource = self;
it.delegate = self;
}]];
if (self.isSimulator) {
NSString *result = @"127.0.0.1";
[DoricJSRemoteExecutor configIp:result];
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
} else {
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [DoricContextManager.instance aliveContexts].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSValue *value = [DoricContextManager.instance aliveContexts][(NSUInteger) indexPath.row];
DoricContext *context = value.nonretainedObjectValue;
NSString *path = context.source;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = path;
return cell;
}
- (BOOL)isSimulator {
return TARGET_OS_SIMULATOR == 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
@end

View File

@ -29,6 +29,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong) dispatch_semaphore_t semaphore;
+ (void)configIp:(NSString *)ip;
- (void)close;
@end

View File

@ -25,7 +25,7 @@
#import "DoricJSRemoteArgType.h"
#import "NSString+JsonString.h"
static NSString * const kUrlStr = @"ws://192.168.24.240:2080";
static NSString *debuggerAddress = @"";
typedef id (^Block0)(void);
typedef id (^Block1)(id arg0);
@ -182,6 +182,10 @@ - (NSDictionary *)dicForArg:(id)arg {
return dic;
}
+ (void)configIp:(NSString *)ip {
debuggerAddress = [[@"ws://" stringByAppendingString:ip] stringByAppendingString:@":2080"];
}
- (void)close {
[self.srWebSocket close];
}
@ -189,7 +193,7 @@ - (void)close {
#pragma mark - Properties
- (SRWebSocket *)srWebSocket {
if (!_srWebSocket) {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:kUrlStr] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:debuggerAddress] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
_srWebSocket = [[SRWebSocket alloc] initWithURLRequest:request];
_srWebSocket.delegate = self;
[_srWebSocket open];

View File

@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricWSClient : NSObject
- (instancetype)initWithUrl:(NSString *)url;
- (void)send:(NSString *)command;
- (void)close;
@end

View File

@ -75,6 +75,10 @@ - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reas
DoricLog(@"webSocketdidCloseWithCode");
}
- (void)send:(NSString *)command {
[_websocket send:command];
}
- (void)close {
[self.websocket close];
}

View File

@ -24,6 +24,7 @@
#import <AVFoundation/AVFoundation.h>
#import <DoricCore/Doric.h>
#import <DoricDevkit/DoricDev.h>
#import "DoricJSRemoteExecutor.h"
@interface QRScanViewController () <AVCaptureMetadataOutputObjectsDelegate>
@property(strong, nonatomic) AVCaptureDevice *device;
@ -104,6 +105,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:
NSString *result = qrObject.stringValue;
NSLog(@"Scan result is %@", result);
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
[DoricJSRemoteExecutor configIp:result];
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
[self.navigationController popViewControllerAnimated:NO];
}

View File

@ -7,8 +7,8 @@
//
#import <DoricCore/Doric.h>
#import <DoricDevkit/QRScanViewController.h>
#import <DoricDevkit/DoricDev.h>
#import <DoricDevkit/DoricDevViewController.h>
#import "ViewController.h"
@ -68,13 +68,7 @@ - (BOOL)isSimulator {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
if (self.isSimulator) {
NSString *result = @"127.0.0.1";
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
} else {
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
}
[self.navigationController pushViewController:[DoricDevViewController new] animated:NO];
return;
}
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];