|
@@ -23,6 +23,8 @@ WHPingDelegate
|
|
|
dispatch_queue_t initProxyQueue;
|
|
|
|
|
|
WHPingTester *whPingTester;
|
|
|
+
|
|
|
+ BOOL didRuiYunInitOkType;
|
|
|
}
|
|
|
|
|
|
@property (nonatomic, strong) NSTimer *connectCheckTimer;
|
|
@@ -147,8 +149,7 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
#pragma mark 初始化瑞云的SDK等
|
|
|
- (void)initRuiyunSDKFun{
|
|
|
|
|
|
- bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
- if(connected){
|
|
|
+ if(didRuiYunInitOkType){
|
|
|
[self onConnectFun];
|
|
|
return;
|
|
|
}
|
|
@@ -173,11 +174,44 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
[NSFileManager.defaultManager createDirectoryAtURL:logUrl withIntermediateDirectories:YES attributes:NULL error:NULL];
|
|
|
}
|
|
|
|
|
|
+ KWeakSelf
|
|
|
dispatch_async(initProxyQueue, ^{
|
|
|
NSData *sdnInfo = [NSData dataWithContentsOfURL:[[NSBundle.mainBundle bundleURL] URLByAppendingPathComponent:@"planet.1ali_3ry_peer"]];
|
|
|
|
|
|
/// 1. 初始化代理库
|
|
|
[RaylinkProxy.sharedManager initProxy:logUrl.path rootSdnInfo:sdnInfo];
|
|
|
+
|
|
|
+ self->didRuiYunInitOkType = YES;
|
|
|
+
|
|
|
+ /// 启动定时器监听 SND 连接状态
|
|
|
+ self.connectCheckTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
|
|
+
|
|
|
+ /// 2. 监听SDN 连接状态
|
|
|
+ bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
+ if (self.sdnConnected == connected) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.sdnConnected = connected;
|
|
|
+ if (self.sdnConnected) {
|
|
|
+
|
|
|
+ [weakSelf onConnectFun];
|
|
|
+ [self->_connectCheckTimer invalidate];
|
|
|
+
|
|
|
+ //self.sdnConnectStateLab.text = @"SDN state: Connected";
|
|
|
+ //self.sdnIDLab.text = [@"My SDN ID: " stringByAppendingString:[RaylinkProxy.sharedManager getSdnId]];
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //self.sdnConnectStateLab.text = @"SDN state: Connectting";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [[NSRunLoop currentRunLoop] addTimer:self.connectCheckTimer forMode:NSRunLoopCommonModes];
|
|
|
+ [[NSRunLoop currentRunLoop] run];
|
|
|
+
|
|
|
});
|
|
|
|
|
|
|
|
@@ -189,62 +223,16 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
NSLog(@"accept ok %d",self.serverSocket.localPort);
|
|
|
}
|
|
|
|
|
|
- KWeakSelf
|
|
|
- /// 启动定时器监听 SND 连接状态
|
|
|
- self.connectCheckTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
|
|
-
|
|
|
- /// 2. 监听SDN 连接状态
|
|
|
- bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
- if (self.sdnConnected == connected) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- self.sdnConnected = connected;
|
|
|
-
|
|
|
- if (self.sdnConnected) {
|
|
|
-
|
|
|
- [weakSelf onConnectFun];
|
|
|
- [self->_connectCheckTimer invalidate];
|
|
|
-
|
|
|
- //self.sdnConnectStateLab.text = @"SDN state: Connected";
|
|
|
- //self.sdnIDLab.text = [@"My SDN ID: " stringByAppendingString:[RaylinkProxy.sharedManager getSdnId]];
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- //self.sdnConnectStateLab.text = @"SDN state: Connectting";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }];
|
|
|
-
|
|
|
-
|
|
|
-// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
-// mainBlock(^{
|
|
|
-// [self onConnectFun];
|
|
|
-// });
|
|
|
-// });
|
|
|
}
|
|
|
|
|
|
|
|
|
- (void)onConnectFun{
|
|
|
|
|
|
- // 2. 监听SDN 连接状态
|
|
|
-// bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
-//
|
|
|
-// HLog(@"协助瑞云看日志onConnectFun isSdnConnected:%d",connected);
|
|
|
-//
|
|
|
-// if(!connected){
|
|
|
-// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
-// mainBlock(^{
|
|
|
-// [self onConnectFun];
|
|
|
-// });
|
|
|
-// });
|
|
|
-//
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
- if (self.peerConnected == YES) {
|
|
|
+ if (self.peerConnected == YES
|
|
|
+ && _Pre_sdnId
|
|
|
+ && ![_Pre_sdnId isEqualToString:self.DeviceThirdIdMod.data.sdnId]) {
|
|
|
//[self disconnect];
|
|
|
+
|
|
|
//return;
|
|
|
}
|
|
|
|