123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- //
- // CloudPhoneViewController+RBD.m
- // VclustersGemini
- //
- // Created by APPLE on 2021/8/16.
- // Copyright © 2021 APPLE. All rights reserved.
- //
- #import "PlayerViewController+RBD.h"
- #import "CloudPhoneModel.h"
- #import <RCCloudPhoneSDK/RCCommandChannel.h>
- #import "AppDelegate.h"
- #import "PhoneP2PModel.h"
- #import "P2PDataManager.h"
- #import "FLSocketManager.h"
- #import <objc/runtime.h>
- #import "UseAccountManage.h"
- #import "SafeForKey.h"
- @interface PlayerViewController(RBD)
- @end
- @implementation PlayerViewController(RBD)
- @dynamic commandChannelManager;
- @dynamic businessCommandChannelManager;
- - (void)setCommandChannelManager:(RCCommandChannelManager *)commandChannelManager {
- objc_setAssociatedObject(self, @selector(commandChannelManager), commandChannelManager, OBJC_ASSOCIATION_RETAIN);
- }
- - (RCCommandChannelManager *)commandChannelManager {
- return objc_getAssociatedObject(self, @selector(commandChannelManager));
- }
- - (void)setBusinessCommandChannelManager:(RCCommandChannelManager *)businessCommandChannelManager {
- objc_setAssociatedObject(self, @selector(businessCommandChannelManager), businessCommandChannelManager, OBJC_ASSOCIATION_RETAIN);
- }
- - (RCCommandChannelManager *)businessCommandChannelManager {
- return objc_getAssociatedObject(self, @selector(businessCommandChannelManager));
- }
- - (void)extensionPhoneGetRBD
- {
- [self showNewIndicator];
- self.deviceModel.startGetRBDTime = [[NSDate date] timeIntervalSince1970];
- self.deviceModel.chaofenResult = NO;
- [self toCheckChaofenStateForShowWithPhone];
- }
- - (void)toCheckChaofenStateForShowWithPhone
- {
- CloudPhoneModel *deviceDcit = self.deviceModel;
- self.rbdNotification = 2;
- /*超分接口调用*/
- [[UseAccountManage shareInstance] extensionCloudPhoneToGetDeviceStatesWithDeviceId:deviceDcit.phoneId coordinatesLat:@"" coordinatesLng:@"" success:^(id _Nonnull responseObject) {
-
- NSDictionary *dict = (NSDictionary *)responseObject;
-
- SuperModel *mod = [[SuperModel alloc] initWithDictionary:dict error:nil];
- NSDictionary *deviceDict = nil;
-
- if ((mod.status && mod.status.integerValue == 0) || (mod.status && mod.status.integerValue == 6001)) {
- if ([[dict allKeys] containsObject:@"data"])
- {
- deviceDict= [[NSDictionary alloc] initWithDictionary:[dict objectForKey:@"data"]];
- }
- }
-
- if (CODE == 0) {
- PhoneP2PModel *model = [[PhoneP2PModel alloc] initWithDictionary:deviceDict error:nil];
- if (model.phoneId != self.deviceModel.phoneId) {
- return;
- }
- if (model.phoneId != self.deviceModel.phoneId) {
- return;
- }
- model.phoneId = deviceDcit.phoneId;
- model.ctime = [[NSDate date] timeIntervalSince1970];
- [[P2PDataManager shareInstance] saveOrUpdateRecoderWithModel:model];
- HLog(@"\n----超分正常----");
- if ([[deviceDict allKeys] containsObject:@"sn"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"sn"] forKey:@"sn"];
- }
- if ([[deviceDict allKeys] containsObject:@"internetVideoPort"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"internetVideoPort"] forKey:@"internetVideoPort"];
- }
- if ([[deviceDict allKeys] containsObject:@"internetBusinessPort"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"internetBusinessPort"] forKey:@"internetBusinessPort"];
- }
- if ([[deviceDict allKeys] containsObject:@"internetIp"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"internetIp"] forKey:@"internetIp"];
- }
- if ([[deviceDict allKeys] containsObject:@"roomInternetIp"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"roomInternetIp"] forKey:@"roomInternetIp"];
- }
- if ([[deviceDict allKeys] containsObject:@"vpnStatus"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"vpnStatus"] forKey:@"vpnStatus"];
- }
- if ([[deviceDict allKeys] containsObject:@"virtualKeyStatus"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"virtualKeyStatus"] forKey:@"virtualKeyStatus"];
- }
- if ([[deviceDict allKeys] containsObject:@"videoCode"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"videoCode"] forKey:@"videoCode"];
- }
- if ([[deviceDict allKeys] containsObject:@"usageHabit"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"usageHabit"] forKey:@"usageHabit"];
- }
- if ([[deviceDict allKeys] containsObject:@"deviceBoard"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"deviceBoard"] forKey:@"deviceBoard"];
- }
- if ([[deviceDict allKeys] containsObject:@"internetHttps"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"internetHttps"] forKey:@"internetHttps"];
- }
- if ([[deviceDict allKeys] containsObject:@"internetHttp"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"internetHttp"] forKey:@"internetHttp"];
- }
- if ([[deviceDict allKeys] containsObject:@"localIp"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"localIp"] forKey:@"localIp"];
- }
- if ([[deviceDict allKeys] containsObject:@"cardToken"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"cardToken"] forKey:@"cardToken"];
- }
- if ([[deviceDict allKeys] containsObject:@"pushFlowCode"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"pushFlowCode"] forKey:@"pushFlowCode"];
- }
- if ([[deviceDict allKeys] containsObject:@"resolvingPower"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"resolvingPower"] forKey:@"resolvingPower"];
- }
- if ([[deviceDict allKeys] containsObject:@"high"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"high"] forKey:@"high"];
- }
- if ([[deviceDict allKeys] containsObject:@"width"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"width"] forKey:@"width"];
- }
- if ([[deviceDict allKeys] containsObject:@"dpi"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"dpi"] forKey:@"dpi"];
- }
- if ([[deviceDict allKeys] containsObject:@"vpnMode"])
- {
- [deviceDcit setValue:[deviceDict objectForKey:@"vpnMode"] forKey:@"vpnMode"];
- }
-
- HLog(@"__________连接000000__________deviceModel.cardToken = %@ 新",self.deviceModel.cardToken);
-
- [self toConnectDeice];
- }else if(CODE == 5201 || CODE == 5200) {
- double nowTime = [[NSDate date] timeIntervalSince1970];
-
- if (nowTime - self.deviceModel.startGetRBDTime < 30 - 1)
- {
- if ([FLSocketManager shareManager].fl_socketStatus == FLSocketStatusReceived || [FLSocketManager shareManager].fl_socketStatus == FLSocketStatusConnected){
- self.chaofenDeviceModel = self.deviceModel;
- self.chaofenDeviceModel.chaofenPhoneIndex = self.phoneIndex;
- double nowTime = [[NSDate date] timeIntervalSince1970];
- double delayTime = 30 - (nowTime - self.deviceModel.startGetRBDTime);
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (self.chaofenDeviceModel.chaofenResult == NO) {
- [self removeNewIndicator];
-
- [[iToast makeText:@"云机优化中,请稍后重试"] show];
- [self exitPlayerView];
- }
- });
- }else{
- /*继续询问服务器*/
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self toCheckChaofenStateForShowWithPhone];
- });
- }
- }
- else
- {
- [self removeNewIndicator];
-
- [[iToast makeText:@"云机优化中,请稍后重试"] show];
- [self exitPlayerView];
- }
- }
- // else if(CODE == 5200) {
- // self.chaofenDeviceModel = deviceDcit;
- //
- // double nowTime = [[NSDate date] timeIntervalSince1970];
- // double delayTime = 30 - (nowTime - deviceDcit.startGetRBDTime);
- //
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // if (self.chaofenDeviceModel.chaofenResult == NO) {
- // [self removeLoadingWithTipsView];
- // [[iToast makeText:@"云机优化中,请稍后重试"] show];
- // }
- // });
- // }
- else if (5203 == CODE){/*排队中*/
- NSString *msg = MSG.length > 0 ? MSG : @"正在排队中,请稍等";
- [[iToast makeText:msg] show];
- [self removeNewIndicator];
- [self exitPlayerView];
- }
- else {
- [self removeNewIndicator];
- [self exitPlayerView];
- [[iToast makeText:@"云手机连接超时,请稍后再试!"] show];
- }
- } faild:^(NSError * _Nonnull error) {
- [self removeNewIndicator];
- [self exitPlayerView];
- [[iToast makeText:@"云手机连接超时,请稍后再试!"] show];
- }];
- }
- - (void)toConnectDeice
- {
- self.canControl = YES;
- //清空WebSocket连接
- [self.commandChannelManager rc_close];
- [self.businessCommandChannelManager rc_close];
-
- /*传入IP与port*/
- self.ip = self.deviceModel.internetIp;
- self.internetVideoPort = self.deviceModel.internetVideoPort;
- self.vpnStatus = self.deviceModel.vpnStatus;
- self.internetHttp = self.deviceModel.internetHttp;
-
- if (self.deviceModel.width > 200 && self.deviceModel.high > 200) {
- ksharedAppDelegate.couldPhone_W_PHONE = self.deviceModel.width;
- ksharedAppDelegate.couldPhone_H_PHONE = self.deviceModel.high;
- }else{
- if ([self.deviceModel.resolvingPower isEqualToString:@"720"]) {
- ksharedAppDelegate.couldPhone_W_PHONE = 720;
- ksharedAppDelegate.couldPhone_H_PHONE = 1280;
- }else{
- ksharedAppDelegate.couldPhone_W_PHONE = 1080;
- ksharedAppDelegate.couldPhone_H_PHONE = 1920;
- }
- }
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- //设置WebSocket
- //初始化指令通道
- [self opencommandChannelManagerrc_openURL];
-
- //初始化业务通道
- [self openbusinessCommandChannelManagerrc_openURL];
- });
-
- if(self.deviceModel.videoCode && [self.deviceModel.videoCode isEqualToString:@"H265"])
- {
- self.isSupportH265Type = YES;
- }
- else
- {
- self.isSupportH265Type = NO;
- }
-
- if ([self isEqual:self.navigationController.topViewController])
- {
- globalBlock(^{
- // 初始化成功后连接
- @synchronized (self) {
- if ([self initVideoServer])
- {
- [self connectVideoServer];
- }
- }
- });
- }
- }
- - (void)extensionRBDGetRbdDeviceNotification:(NSNotification *)notification
- {
- if (self.rbdNotification != 2) {
- return;
- }
- self.rbdNotification = 0;
- double nowTime = [[NSDate date] timeIntervalSince1970];
- NSDictionary *dict = [notification userInfo];
-
- if ([[dict allKeys] containsObject:@"data"])
- {
- NSDictionary *data = [dict objectForKey:@"data"];
-
- CloudPhoneModel *deviceModel = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:self.chaofenDeviceModel.chaofenPhoneIndex];
-
- NSString *userCardIdStr = [NSString stringWithFormat:@"%@",[data safeStringForKey:@"userCardId"]];
- //cardState string 0:成功,1:失败
- NSString *cardStateStr = [NSString stringWithFormat:@"%@",[data safeStringForKey:@"cardState"]];
-
- if (userCardIdStr.intValue == self.chaofenDeviceModel.userCardId) { //当sn相同,userCardIdStr相同,表示同一个设备在进行修改
- self.chaofenDeviceModel.chaofenResult = YES;
- }
-
- //超分成功了,继续走成功的流程(比较sn, userCardId字段相等,且超分成功,时间在30S之内)
- if ([cardStateStr isEqualToString:@"0"] && ((nowTime - self.chaofenDeviceModel.startGetRBDTime) <= 30) && (userCardIdStr.intValue == self.chaofenDeviceModel.userCardId)) {
- PhoneP2PModel *model = [[PhoneP2PModel alloc] initWithDictionary:data error:nil];
- if (deviceModel.phoneId != model.phoneId) {
- return;
- }
-
- model.phoneId = deviceModel.phoneId;
- model.ctime = [[NSDate date] timeIntervalSince1970];
- [[P2PDataManager shareInstance] saveOrUpdateRecoderWithModel:model];
- // NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- // if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- // {
- // /*判断数据库中有没有对应phoneid*/
- // NSString* username = [dictLogin objectForKey:@"userName"];
- // NSString * bg_tableName = P2PModelList_bg_tableName(username);
- // //先显示本地缓存数据
- // NSArray* finfAlls = [PhoneP2PListModel bg_findAll:bg_tableName];
- // if (finfAlls && finfAlls.count >0) {
- // PhoneP2PListModel *listMod = finfAlls[0];
- // BOOL haveFind = NO;
- // for (PhoneP2PModel *p2pModel in listMod.data) {
- // if (p2pModel.phoneId == deviceModel.phoneId){
- // PhoneP2PModel *model = [[PhoneP2PModel alloc] initWithDictionary:data error:nil];
- // model.ctime = [[NSDate date] timeIntervalSince1970];
- // model.phoneId = deviceModel.phoneId;
- // [listMod.data removeObject:p2pModel];
- // [listMod.data addObject:model];
- // [listMod bg_cover];
- // haveFind = YES;
- // break;
- // }
- // }
- // if (haveFind == NO) {
- // PhoneP2PModel *model = [[PhoneP2PModel alloc] initWithDictionary:data error:nil];
- // model.ctime = [[NSDate date] timeIntervalSince1970];
- // model.phoneId = deviceModel.phoneId;
- // [listMod.data addObject:model];
- // [listMod bg_cover];
- // }
- // }else{
- // PhoneP2PListModel *listmodel = [[PhoneP2PListModel alloc] init];
- // PhoneP2PModel *model = [[PhoneP2PModel alloc] initWithDictionary:data error:nil];
- // model.ctime = [[NSDate date] timeIntervalSince1970];
- // model.phoneId = deviceModel.phoneId;
- // listmodel.data = [[NSMutableArray alloc] initWithObjects:model, nil];
- // listmodel.bg_tableName = bg_tableName;
- // [listmodel bg_cover];
- // }
- // }
- //继续往下进入超分成功0的流程
- if ([[data allKeys] containsObject:@"sn"])
- {
- [deviceModel setValue:[data objectForKey:@"sn"] forKey:@"sn"];
- }
- if ([[data allKeys] containsObject:@"internetVideoPort"])
- {
- [deviceModel setValue:[data objectForKey:@"internetVideoPort"] forKey:@"internetVideoPort"];
- }
- if ([[data allKeys] containsObject:@"internetBusinessPort"])
- {
- [deviceModel setValue:[data objectForKey:@"internetBusinessPort"] forKey:@"internetBusinessPort"];
- }
- if ([[data allKeys] containsObject:@"internetIp"])
- {
- [deviceModel setValue:[data objectForKey:@"internetIp"] forKey:@"internetIp"];
- }
- if ([[data allKeys] containsObject:@"roomInternetIp"])
- {
- [deviceModel setValue:[data objectForKey:@"roomInternetIp"] forKey:@"roomInternetIp"];
- }
- if ([[data allKeys] containsObject:@"vpnStatus"])
- {
- [deviceModel setValue:[data objectForKey:@"vpnStatus"] forKey:@"vpnStatus"];
- }
- if ([[data allKeys] containsObject:@"virtualKeyStatus"])
- {
- [deviceModel setValue:[data objectForKey:@"virtualKeyStatus"] forKey:@"virtualKeyStatus"];
- }
- if ([[data allKeys] containsObject:@"videoCode"])
- {
- [deviceModel setValue:[data objectForKey:@"videoCode"] forKey:@"videoCode"];
- }
- if ([[data allKeys] containsObject:@"usageHabit"])
- {
- [deviceModel setValue:[data objectForKey:@"usageHabit"] forKey:@"usageHabit"];
- }
- if ([[data allKeys] containsObject:@"deviceBoard"])
- {
- [deviceModel setValue:[data objectForKey:@"deviceBoard"] forKey:@"deviceBoard"];
- }
- if ([[data allKeys] containsObject:@"internetHttps"])
- {
- [deviceModel setValue:[data objectForKey:@"internetHttps"] forKey:@"internetHttps"];
- }
- if ([[data allKeys] containsObject:@"internetHttp"])
- {
- [deviceModel setValue:[data objectForKey:@"internetHttp"] forKey:@"internetHttp"];
- }
- if ([[data allKeys] containsObject:@"localIp"])
- {
- [deviceModel setValue:[data objectForKey:@"localIp"] forKey:@"localIp"];
- }
- if ([[data allKeys] containsObject:@"cardToken"])
- {
- [deviceModel setValue:[data objectForKey:@"cardToken"] forKey:@"cardToken"];
- }
- if ([[data allKeys] containsObject:@"pushFlowCode"])
- {
- [deviceModel setValue:[data objectForKey:@"pushFlowCode"] forKey:@"pushFlowCode"];
- }
- if ([[data allKeys] containsObject:@"resolvingPower"])
- {
- [deviceModel setValue:[data objectForKey:@"resolvingPower"] forKey:@"resolvingPower"];
- }
- if ([[data allKeys] containsObject:@"high"])
- {
- [deviceModel setValue:[data objectForKey:@"high"] forKey:@"high"];
- }
- if ([[data allKeys] containsObject:@"width"])
- {
- [deviceModel setValue:[data objectForKey:@"width"] forKey:@"width"];
- }
- if ([[data allKeys] containsObject:@"dpi"])
- {
- [deviceModel setValue:[data objectForKey:@"dpi"] forKey:@"dpi"];
- }
- if ([[data allKeys] containsObject:@"vpnMode"])
- {
- [deviceModel setValue:[data objectForKey:@"vpnMode"] forKey:@"vpnMode"];
- }
-
- [self toConnectDeice];
- }
- else
- {
- [self removeNewIndicator];
- [self exitPlayerView];
- [[iToast makeText:@"云手机连接超时,请稍后再试!"] show];
- }
- }
- }
- @end
|