add doric dev vc
This commit is contained in:
		@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- (void)connectDevKit:(NSString *)url;
 | 
					- (void)connectDevKit:(NSString *)url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void)sendDevCommand:(NSString *)command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)disconnectDevKit;
 | 
					- (void)disconnectDevKit;
 | 
				
			||||||
@end
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,10 @@ - (void)connectDevKit:(NSString *)url {
 | 
				
			|||||||
    self.wsclient = [[DoricWSClient alloc] initWithUrl:url];
 | 
					    self.wsclient = [[DoricWSClient alloc] initWithUrl:url];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void)sendDevCommand:(NSString *)command {
 | 
				
			||||||
 | 
					    [self.wsclient send:command];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)disconnectDevKit {
 | 
					- (void)disconnectDevKit {
 | 
				
			||||||
    if (self.wsclient) {
 | 
					    if (self.wsclient) {
 | 
				
			||||||
        [self.wsclient close];
 | 
					        [self.wsclient close];
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										29
									
								
								doric-iOS/Devkit/Classes/DoricDevViewController.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								doric-iOS/Devkit/Classes/DoricDevViewController.h
									
									
									
									
									
										Normal 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										81
									
								
								doric-iOS/Devkit/Classes/DoricDevViewController.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								doric-iOS/Devkit/Classes/DoricDevViewController.m
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -29,6 +29,8 @@ NS_ASSUME_NONNULL_BEGIN
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@property(nonatomic, strong) dispatch_semaphore_t semaphore;
 | 
					@property(nonatomic, strong) dispatch_semaphore_t semaphore;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ (void)configIp:(NSString *)ip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)close;
 | 
					- (void)close;
 | 
				
			||||||
@end
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@
 | 
				
			|||||||
#import "DoricJSRemoteArgType.h"
 | 
					#import "DoricJSRemoteArgType.h"
 | 
				
			||||||
#import "NSString+JsonString.h"
 | 
					#import "NSString+JsonString.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static NSString * const kUrlStr = @"ws://192.168.24.240:2080";
 | 
					static NSString *debuggerAddress = @"";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef id (^Block0)(void);
 | 
					typedef id (^Block0)(void);
 | 
				
			||||||
typedef id (^Block1)(id arg0);
 | 
					typedef id (^Block1)(id arg0);
 | 
				
			||||||
@@ -182,6 +182,10 @@ - (NSDictionary *)dicForArg:(id)arg {
 | 
				
			|||||||
    return dic;
 | 
					    return dic;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ (void)configIp:(NSString *)ip {
 | 
				
			||||||
 | 
					    debuggerAddress = [[@"ws://" stringByAppendingString:ip] stringByAppendingString:@":2080"];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)close {
 | 
					- (void)close {
 | 
				
			||||||
    [self.srWebSocket close];
 | 
					    [self.srWebSocket close];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -189,7 +193,7 @@ - (void)close {
 | 
				
			|||||||
#pragma mark - Properties
 | 
					#pragma mark - Properties
 | 
				
			||||||
- (SRWebSocket *)srWebSocket {
 | 
					- (SRWebSocket *)srWebSocket {
 | 
				
			||||||
    if (!_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 = [[SRWebSocket alloc] initWithURLRequest:request];
 | 
				
			||||||
        _srWebSocket.delegate = self;
 | 
					        _srWebSocket.delegate = self;
 | 
				
			||||||
        [_srWebSocket open];
 | 
					        [_srWebSocket open];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
 | 
				
			|||||||
@interface DoricWSClient : NSObject
 | 
					@interface DoricWSClient : NSObject
 | 
				
			||||||
- (instancetype)initWithUrl:(NSString *)url;
 | 
					- (instancetype)initWithUrl:(NSString *)url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void)send:(NSString *)command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)close;
 | 
					- (void)close;
 | 
				
			||||||
@end
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,6 +75,10 @@ - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reas
 | 
				
			|||||||
    DoricLog(@"webSocketdidCloseWithCode");
 | 
					    DoricLog(@"webSocketdidCloseWithCode");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void)send:(NSString *)command {
 | 
				
			||||||
 | 
					    [_websocket send:command];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)close {
 | 
					- (void)close {
 | 
				
			||||||
    [self.websocket close];
 | 
					    [self.websocket close];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@
 | 
				
			|||||||
#import <AVFoundation/AVFoundation.h>
 | 
					#import <AVFoundation/AVFoundation.h>
 | 
				
			||||||
#import <DoricCore/Doric.h>
 | 
					#import <DoricCore/Doric.h>
 | 
				
			||||||
#import <DoricDevkit/DoricDev.h>
 | 
					#import <DoricDevkit/DoricDev.h>
 | 
				
			||||||
 | 
					#import "DoricJSRemoteExecutor.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@interface QRScanViewController () <AVCaptureMetadataOutputObjectsDelegate>
 | 
					@interface QRScanViewController () <AVCaptureMetadataOutputObjectsDelegate>
 | 
				
			||||||
@property(strong, nonatomic) AVCaptureDevice *device;
 | 
					@property(strong, nonatomic) AVCaptureDevice *device;
 | 
				
			||||||
@@ -104,6 +105,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:
 | 
				
			|||||||
        NSString *result = qrObject.stringValue;
 | 
					        NSString *result = qrObject.stringValue;
 | 
				
			||||||
        NSLog(@"Scan result is %@", result);
 | 
					        NSLog(@"Scan result is %@", result);
 | 
				
			||||||
        [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
 | 
					        [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
 | 
				
			||||||
 | 
					        [DoricJSRemoteExecutor configIp:result];
 | 
				
			||||||
        ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
 | 
					        ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM);
 | 
				
			||||||
        [self.navigationController popViewControllerAnimated:NO];
 | 
					        [self.navigationController popViewControllerAnimated:NO];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#import <DoricCore/Doric.h>
 | 
					#import <DoricCore/Doric.h>
 | 
				
			||||||
#import <DoricDevkit/QRScanViewController.h>
 | 
					
 | 
				
			||||||
#import <DoricDevkit/DoricDev.h>
 | 
					#import <DoricDevkit/DoricDevViewController.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#import "ViewController.h"
 | 
					#import "ViewController.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,13 +68,7 @@ - (BOOL)isSimulator {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 | 
					- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 | 
				
			||||||
    if (indexPath.row == 0) {
 | 
					    if (indexPath.row == 0) {
 | 
				
			||||||
        if (self.isSimulator) {
 | 
					        [self.navigationController pushViewController:[DoricDevViewController new] animated:NO];
 | 
				
			||||||
            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];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
 | 
					    NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user