123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- //
- // webRtcManager.m
- // 双子星云手机
- //
- // Created by xd h on 2024/9/5.
- //
- #import "webRtcManager.h"
- #import "webRtcManager+StatisticsReport.h"
- #import "RcGameWQKeyChain.h"
- #import "errorAlertTool.h"
- #import "webRtcManager+downloadNasFile.h"
- @interface webRtcManager ()<MediaStreamClientEventsDelegate>
- {
- NSMutableArray *commandSendCheckArr;//需要检测任务是否发出的的指令
- }
- //第一次链接设备 要发送指令信息 实现单点登录
- @property (nonatomic, assign)BOOL didSendfristMsg;
- @end
- @implementation webRtcManager
- + (instancetype)shareManager {
- static webRtcManager *_instance;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _instance = [[self alloc] init];
- });
- return _instance;
- }
- - (instancetype)init {
- if (self = [super init]) {
- //[self registeNotification];
-
- _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
- [_mediaStream setEventDelegate:self];
- }
- return self;
- }
- #pragma mark 关闭链接
- - (void)closeLinkWebRtcFun
- {
- [_mediaStream disconnect];
- }
- #pragma mark 开始链接
- - (void)beginToLinkWebRtcFun
- {
- if(ksharedAppDelegate.isWebSockLinkOKAginType
- || !ksharedAppDelegate.DeviceWebRtcMsgMod){
- return;
- }
-
- webRtcMsgModel * _webRtcMsgMod = ksharedAppDelegate.DeviceWebRtcMsgMod;
-
- //链接用
- NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
- NSURL *url = [NSURL URLWithString:signallingUrl];
-
- //ice用
- NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
-
- NSMutableDictionary *ice = [NSMutableDictionary new];
- if(iceUrl){
- [ice setValue:iceUrl forKey:@"CHINANET"];
- [ice setValue:iceUrl forKey:@"CMNET"];
- [ice setValue:iceUrl forKey:@"UNICOM"];
- }
-
- NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
-
-
- NSInteger result = [_mediaStream startUploadChannel:url ice:ice sn:roomName token:@"vclusters"];
-
- // NSInteger result = [_mediaStream start:url
- // ice:ice
- // sn:roomName
- // direct:0
- // fmt:1//1(h264) 5(h265)
- // videoWidth:1080.0
- // videoHeight:1920.0
- // fps:30
- // bitrate:3000
- // cardWidth:0
- // cardHeight:0
- // cardDensity:0
- // token:@"vclusters"];
-
- HLog(@"result:%ld",result)
- [_mediaStream setShouldGetStats:YES];
- }
- - (void)relinkWebRtcFun{
- [self beginToLinkWebRtcFun];
- }
- #pragma mark webrtc P2P通道发送消息
- - (void)send_data:(NSString *)dataStr
- {
- [_mediaStream sendData:dataStr];
- }
- #pragma mark 盒子链接成功后需要处理的各种各样事情
- - (void)handlAllMsgAfterDidLinkFun
- {
- _isRebootIngType = NO;
- _isResetingType = NO;
- _isChangeBoxType = NO;
-
- ksharedAppDelegate.isWebSockLinkOKAginType = YES;
-
- //获取云机尺寸 兼容 720*1080 &1080*1920 不同分辨率的展示和触控
- NSString *getPhoneSizeStr = [RCCommandHelp getPhoneSizecommand];
- [self send_data:getPhoneSizeStr];
-
- //判断是否为需要改机
- BOOL isNeedRandomChangeParams = [HWDataManager getBoolWithKey:Const_need_random_Change_Params];
- if(isNeedRandomChangeParams)
- {
- NSString *commondStr = @"{\"type\":\"randomChangeParams\"}";
- [self send_data:commondStr];
-
- [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:NO];
- }
-
- [self fristConnectNeedGiveAMsgFun];
-
- [self updateCopydata];
- // 报链接失败 后面又连接上了
- [[errorAlertTool shareInstance] dismissErrorAlertFun];
-
- //处理相册备份
-
- //获取磁盘外挂
- [self getExtraFilesListFun];
-
- [self getBaseInfoFun];
-
- [self getTvStatusFun];
- }
- #pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
- - (void)fristConnectNeedGiveAMsgFun{
-
- if(!_didSendfristMsg )
- {
- [self getSysInfoFun];
-
- NSString *curOaidStr = [RcGameWQKeyChain getOaidStringFun];
- if(!curOaidStr){
- curOaidStr = @"";
- }
-
- //未调通挤下线
- NSString *commondStr = [[NSString alloc] initWithFormat:@"{\"type\":\"login\",\"value\":\"%@\"}",curOaidStr];
- [self send_data:commondStr];
- [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
-
- _didSendfristMsg = YES;
-
- [self getPreferredLanguage];
-
- NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
- [self send_data:commondStr2];
- }
- }
- #pragma mark 语言和市区 同步云机
- -(void)getPreferredLanguage
- {//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
- // iOS 获取设备当前语言的代码
- NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
- HLog(@"当前语言:%@", preferredLanguage);
- //en-US 英文 ja-JP 日文
-
- NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
- NSLog(@"arLanguages:%@",arLanguages);
- ///获取设备当前地区的代码和APP语言环境
- NSString *languageCode = [NSLocale preferredLanguages][0];
-
-
- //目前支持 中文(简体 繁体) 英文 日语
- if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
- {
- preferredLanguage = @"zh-CN";
- }
- else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
- {
- preferredLanguage = @"zh-HK";
- }
- else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
- {
- preferredLanguage = @"ja-JP";
- }
- else{
- preferredLanguage = @"en-US";
- }
-
- // if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
- // preferredLanguage = languageCode;
- // }
- // else{
- // preferredLanguage = @"en-US";
- // }
-
- NSString*gmtStr = [self UTCOffset];
- HLog(@"%@",gmtStr);
- // //获取名字,如“GMT+08:00
-
- NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
-
- [self send_data:commondStr];
-
- }
- #pragma mark 获取云机系统镜像等信息
- - (void)getSysInfoFun
- {
- NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
- [self send_data:commondStr];
- }
- -(NSString *)UTCOffset {
- NSTimeZone *localTZ = [NSTimeZone localTimeZone];
- float offset = localTZ.secondsFromGMT/3600.0;
- if(offset > 0){
- return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
- }
- return [NSString stringWithFormat:@"Etc/GMT%g",offset];
- }
- #pragma mark 收到系统信息消息回调处理
- - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
- couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
- //[[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
-
- // NSString *hostImgVer = model.data.data.hostImgVer;
- // NSString *MyNewVersion = model.data.data.MyNewVersion;
-
- NSString *hostImgVer = model.data.hostImgVer;
- NSString *MyNewVersion = model.data.MyNewVersion;
- //test code
- // hostImgVer = @"1.2.3";
- // MyNewVersion = @"1.2.0";
-
- //判断当前版本号 待更新版本
- if (!hostImgVer || hostImgVer.length < 3
- ||!MyNewVersion || MyNewVersion.length < 3) {
- return;
- }
-
- NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
- NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
-
- NSInteger versionArrCount = versionArr.count;
- NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
- NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
-
- BOOL isNeedShowType = NO;
- //判断是否要更新镜像框
- if(maxCount > 0){
- for (int i=0; i<maxCount; i++) {
- NSString * numberStr1 = versionArr[i];
- NSString * numberStr2 = MyNewVersionArr[i];
-
- if(numberStr2.intValue > numberStr1.intValue){
- isNeedShowType =YES;
- break;
- }
- }
- }
-
-
- if(isNeedShowType){
- ksharedAppDelegate.isNeedShowImageNewType = YES;
- }
-
- //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
- if(versionArr.count >= 3)
- {
- NSString * oneStr = versionArr[0];
- NSString * twoStr = versionArr[1];
- NSString * threeStr = versionArr[2];
- if(oneStr.integerValue <=1 && twoStr.integerValue <=3 && threeStr.integerValue <=0){//禁用
- ksharedAppDelegate.DisabledFileTransferType = YES;
-
- if(MyNewVersionArr.count >= 3)
- {
- NSString * newOneStr = MyNewVersionArr[0];
- NSString * newTwoStr = MyNewVersionArr[1];
- NSString * newThreeStr = MyNewVersionArr[2];
-
- if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
- ksharedAppDelegate.isImageNewFor130 = YES;
- }
- else{
- ksharedAppDelegate.isImageNewFor130 = NO;
- }
- }
- }
- else{
- ksharedAppDelegate.DisabledFileTransferType = NO;
- }
- }
-
- [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
- }
- #pragma mark 添加消息重复机制
- -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
- {
- if(!commandSendCheckArr){
- commandSendCheckArr = [NSMutableArray new];
- }
-
- BOOL didAddType = NO;
-
- for (commandSendCheckModel *model in commandSendCheckArr) {
- if([model.type isEqualToString:type]){
- didAddType = YES;
- model.reSendNum = 0;
- model.sendTimerStamp = [iTools getNowTimeStamp];
- break;
- }
- }
-
- if(!didAddType){
- commandSendCheckModel *model = [commandSendCheckModel new];
- model.commandStr = commandStr;
- model.type = type;
- model.reSendNum = 0;
- model.sendTimerStamp = [iTools getNowTimeStamp];
- [commandSendCheckArr addObject:model];
- }
-
- }
- #pragma mark 删除代理确认收到的消息
- -(void)deleteCommandSendTaskFunWith:(NSString*)type
- {
- if(commandSendCheckArr && commandSendCheckArr.count >0){
-
- NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
-
- for (commandSendCheckModel *model in taskArr) {
- if([type isEqualToString:model.type]){
- [commandSendCheckArr removeObject:model];
- }
- }
- }
- }
- #pragma mark 复制手机消息到云机
- - (void)updateCopydata{
- UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
- NSString *str = [pasteboard string];
-
- HLog(@"__________%s______%@____",__func__,str);
-
- if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
- {
- str = nil;
- }
-
- if (str && str.length >0)
- {
- //HLog(@"hxd111 cutting %@",str);
- /*发送数据*/
- NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
- [self send_data:dataStr];
- //pasteboard.string = @"";
- }
-
- }
- #pragma mark 获取云机以及外挂磁盘
- - (void)getExtraFilesListFun
- {
- // NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
- // [self send_data:ExtraCommondStr];
-
- //改走http方案
- [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:nil];/*发送通知*/
- }
- #pragma mark 获取到云机以及外挂磁盘信息
- - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
- {
- cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
- ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:getExtraFilesDoneNotification object:dataDict];/*发送通知*/
- }
- #pragma mark 获取云机基本信息
- - (void)getBaseInfoFun
- {
- NSString *commondStr = @"{\"type\":\"getBaseInfo\"}";
- [self send_data:commondStr];
- }
- #pragma mark 获取到云机基本信息
- - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
- {
- couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
- [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
- }
- #pragma mark 获取到TV投屏状态
- - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
- {
- TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
- ksharedAppDelegate.TvStatusMod = model;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
-
- // if(![model.msg containsString:@"PushStreamBActivity"])
- // {
- // return;
- // }
- //
- // UIViewController*topVc = self.navigationController.viewControllers.lastObject;
- // if([topVc isKindOfClass:[PlayerViewController class]]){
- // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
- // }
- }
- #pragma mark 重启云机
- - (void)needToRebootFun
- {
- NSString *commondStr = @"{\"type\":\"reboot\"}";
- [self send_data:commondStr];
-
- //添加到任务监听
- [self addCommandSendTaskFunWithType:@"reboot" WithCommandStr:commondStr];
-
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restart"];
-
- _isRebootIngType = YES;
- }
- #pragma mark 恢复出厂设置
- - (void)needToResetFun
- {
- NSString *commondStr = @"{\"type\":\"reset\"}";
- [self send_data:commondStr];
-
- //添加到任务监听
- [self addCommandSendTaskFunWithType:@"reset" WithCommandStr:commondStr];
-
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_restore_factory"];
- _isResetingType = YES;
- }
- #pragma mark 获取TV投屏状态
- - (void)getTvStatusFun
- {
- NSString *commondStr = @"{\"type\":\"TvStatus\"}";
- [self send_data:commondStr];
- }
- #pragma mark 关闭TV投屏状态
- - (void)offTvFun
- {
- NSString *commondStr = @"{\"type\":\"TvOff\"}";
- [self send_data:commondStr];
- }
- #pragma mark 开启TV投屏状态
- - (void)onTvFun
- {
- NSString *commondStr = @"{\"type\":\"wakeupTV\"}";
- [self send_data:commondStr];
- }
- #pragma mark 创建备份文件夹
- - (void)createBackupsFolderBy:(NSString*)backupsDefaultPath
- {
- NSString *folderName = backupsDefaultPath;
-
- if(folderName && folderName.length >0){
- NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
- [self send_data:commandStr];
- }
- }
- #pragma mark 获取备份文件夹列表
- - (void)getBackupFolderListFun
- {
- NSString * commandStr = [RCCommandHelp getCreateFolderList];
- [self send_data:commandStr];
- }
- #pragma mark 创建文件夹回调
- - (void)createFolderResponseFun:(NSDictionary *)dataDict
- {
- couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
-
- if(model){
- NSNumber *curNum = [NSNumber numberWithInteger:model.status];
- [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
- }
- }
- - (void)getFolderListResponseFun:(NSDictionary *)dataDict
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
- }
- - (void)searchFileListResponseFun:(NSDictionary *)dataDict
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
- }
- #pragma mark U盘插入相关
- - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
- {
- mainBlock((^{
- extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
-
- NSString *tip = nil;
- if(model.data.event == 0){
- tip = NSLocalizedString(@"disk_insertion_tip",nil);
- [self showInsertPopViewFun:model.data.name];
- }
- else if(model.data.event == 1){
- tip = NSLocalizedString(@"disk_extract_tip",nil);
- }
- else if(model.data.event == 2){
- tip = NSLocalizedString(@"disk_save_extract_tip",nil);
- }
-
- NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
-
- [[iToast makeText:totalTips] show];
- }));
- }
- #pragma mark 显示插入UI弹框
- - (void)showInsertPopViewFun:(NSString*)name
- {
- if(self->curUSBInsertPopV){
- [self->curUSBInsertPopV removeFromSuperview];
- self->curUSBInsertPopV = nil;
- }
-
- self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
-
- [[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
- }
- #pragma mark 收到的webrtc消息处理
- - (void)handleWebRtcMsgResponseBy:(NSData*)message
- {
- if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
- {
- message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
- }
-
- NSError *error = nil;
- NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
- HLog(@"webRtc P2P 通道接收消息:------------------%@",dataDict);
-
- // if([message isKindOfClass:[NSData class]] && [message length] == 0){
- // if(type == RCSocketCloudPhoneReceiveTypeForPong)
- // {
- // [weakSelf keepWebSocketOKFun];
- // }
- // return;
- // }
- //
- // HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
- //
- // if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
- // {
- // message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
- // }
- //
- // NSError *error = nil;
- // NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
-
- if(!dataDict){
- //[weakSelf handleDownloadResponseFunBy:message];
- return;
- }
-
- if(![dataDict isKindOfClass:[NSDictionary class]]){
- //[__NSCFString allKeys] unrecognized selector sent to ins
- return;
- }
-
- NSString *messageType = dataDict[@"type"];
-
- if ([messageType isEqualToString:@"cutting"]) {
- //[[iToast makeText:@"复制成功"] show];
- }
- // else if ([messageType isEqualToString:@"forwardMsgRep"]){/*转发的回复*/
- //
- // cloudPhoneCommonModel *model = [[cloudPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
- // if(!model){
- // return;
- // }
- //
- // if([model.data.msg isEqualToString:@"only one socket"]||
- // [model.data.msg isEqualToString:@"only one socket2"]){
- // [weakSelf deleteCommandSendTaskFunWith:@"offline_notification"];
- // }
- // }
- // else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
- // /*获取指令类型*/
- // NSString *code = nil;
- // if ([[dataDict allKeys] containsObject:@"data"]) {
- // NSDictionary *data = dataDict[@"data"];
- //
- // if([data isKindOfClass:[NSString class]]){
- // NSString * dataStr = (NSString*)data;
- // if([dataStr isEqualToString:@"offline_notification"]){
- // HLog(@"被别人挤下线了");
- // [weakSelf LogoutByOtherFun];
- // }
- //
- // return;
- // }
- // else if ([data isKindOfClass:[NSDictionary class]] && [[data allKeys] containsObject:@"code"]) {
- // code = [data objectForKey:@"code"];
- //
- // if (![code isKindOfClass:[NSString class]]) {
- // code = [NSString stringWithFormat:@"%ld",[code integerValue]];
- // }
- // }
- // }
- //
- // /*获取用户名*/
- // NSString *useName = nil;
- // if ([[dataDict allKeys] containsObject:@"data"]) {
- // NSDictionary *data = dataDict[@"data"];
- // if ([[data allKeys] containsObject:@"userName"]) {
- // //useName = [data objectForKey:@"userName"];
- // }
- // }
- //
- //
- // if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
- // if ([[dataDict allKeys] containsObject:@"data"]) {
- // NSDictionary *data = dataDict[@"data"];
- // if ([[data allKeys] containsObject:@"width"]) {
- // ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
- // }
- // if ([[data allKeys] containsObject:@"height"]) {
- // ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
- // }
- //
- // if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
- // CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
- // ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
- // ksharedAppDelegate.couldPhone_H_PHONE = temp;
- // }
- // }
- // }
- // }
- else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
- //NSString *sn = nil;
-
- if([messageType isEqualToString:@"setPhoneSize"]){
- self.isDiDChangePhoneSizeType = YES;
- }
-
- if ([[dataDict allKeys] containsObject:@"data"]) {
- NSDictionary *data = dataDict[@"data"];
-
- if ([[data allKeys] containsObject:@"status"]) {
- NSInteger status = [[data objectForKey:@"status"] integerValue];
-
- if (status == 0) {/*不是当前设备直接返回*/
- if ([[data allKeys] containsObject:@"width"]) {
- ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
- }
- if ([[data allKeys] containsObject:@"height"]) {
- ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
- }
-
- if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
- CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
- ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
- ksharedAppDelegate.couldPhone_H_PHONE = temp;
- }
- }
- }
- }
- }
- // else if ([messageType isEqualToString:@"sync_wifi"]){
- // [weakSelf sync_wifiBackHandleFun];
- // }
- // else if ([messageType isEqualToString:@"reProduceText"]){
- // if ([[dataDict allKeys] containsObject:@"data"]) {
- // NSDictionary *data = dataDict[@"data"];
- //
- // if ([[data allKeys] containsObject:@"text"]) {
- // NSString *pasteboardStr = [data objectForKey:@"text"];
- // UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
- // pasteboard.string = pasteboardStr;
- // }
- // }
- // }
- // else if ([messageType isEqualToString:@"downAdnInstallRep"]){
- // if ([[dataDict allKeys] containsObject:@"data"]) {
- // NSDictionary *data = dataDict[@"data"];
- //
- // if ([[data allKeys] containsObject:@"status"]) {
- // NSString *status = [data objectForKey:@"status"];
- // if ([status isEqualToString:@"1"]) {
- // mainBlock(^{
- // // [[iToast makeText:@"App下载完成"] show];
- // });
- // }else if ([status isEqualToString:@"0"]){
- // mainBlock(^{
- // //[[iToast makeText:@"App下载中"] show];
- // });
- // }
- // }
- // }
- // }
- // else if ([messageType isEqualToString:@"shakeit"]){
- // HLog(@"\n-----摇一摇成功------");
- // }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
- // HLog(@"\n-----待处理 调起键盘------");
- // // [weakSelf keyboardFeedbackBeanFun];
- // }else if ([messageType isEqualToString:@"FileRandomReady"]
- // ||[messageType isEqualToString:@"FilePartReady"]
- // ){/*申请文件上传得到答复*/
- // [weakSelf applyUploadFileServiceResponseFun:dataDict];
- // }
- // else if ([messageType isEqualToString:@"uploadFileRandomRet"]
- // ||[messageType isEqualToString:@"uploadFilePartRet"]
- // ){/*文件上传得到答复*/
- // [weakSelf upLoadFileFunServiceResponseFun:dataDict];
- // }
- // else if ([messageType isEqualToString:@"backUpFileRandomReady"]
- // ||[messageType isEqualToString:@"backUpPartReady"]
- // ){/*文件备份得到答复*/
- // [weakSelf applyBackupsFileServiceResponseFun:dataDict];
- // }
- // else if ([messageType isEqualToString:@"backUpFileRandomRet"]
- // ||[messageType isEqualToString:@"backUpFilePartRet"]){/*文件备份得到答复*/
- // [weakSelf backupsFileFunServiceResponseFun:dataDict];
- // }
- else if ([messageType isEqualToString:@"getBaseInfo"]){/*获取云机的基本信息*/
- [self getCouldPhoneBaseInfoResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"getSysInfo"]){/*获取云机的系统信息*/
- [self getCouldPhoneSysInfoResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"TvStatus"]){/*获取TV投屏信息*/
- [self getCouldPhoneTvStatusResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"TvOff"]){/*关闭TV投屏*/
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self getTvStatusFun];
- });
- }
- else if ([messageType isEqualToString:@"wakeupTV"]){/*开启TV投屏*/
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self getTvStatusFun];
- });
- }
- else if ([messageType isEqualToString:@"reboot"]){/*重启*/
- //[weakSelf stopForceStartTimerFun];
- }
- else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
- [self createFolderResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
- [self getFolderListResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
- [self searchFileListResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"getExtraFiles"]){/*获取云机产品信息*/
- [self getExtraFilesResponseFun:dataDict];
- }
- else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
- [self getExtraMediaEventResponseFun:dataDict];
- [self getExtraFilesListFun];
- }
- else if ([messageType isEqualToString:@"reset"]){/**/
- [self deleteCommandSendTaskFunWith:@"reset"];
- }
-
- }
- #pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
- #pragma mark 不能再这里函数判断 这个是推拉流的
- -(void)onChangeConnectionStateFromPeerName:(NSString*)peerName didChangeIceConnectionState:(RTCIceConnectionState)state
- {
- HLog(@"channel onChangeConnectionStateFromPeerName: state:%ld",state)
- // switch (state) {
- // case RTCIceConnectionStateConnected:{
- // //链接成功
- // [self handlAllMsgAfterDidLinkFun];
- // }
- // break;
- // case RTCIceConnectionStateCompleted:
- // //链接完成
- // break;
- // case RTCIceConnectionStateFailed:
- // //链接失败
- // break;
- // case RTCIceConnectionStateDisconnected:
- // //链接断开
- // [self relinkWebRtcFun];
- // break;
- // case RTCIceConnectionStateClosed:
- // //链接关闭
- // break;
- //
- // default:
- // break;
- // }
-
- }
- #pragma mark 通道连接状态变化监听
- - (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state
- {
- self.channelState = state;
- switch (state) {
- case RTCDataChannelStateConnecting:
- {
-
- }
- break;
- case RTCDataChannelStateOpen:
- {
- //链接成功
- [self handlAllMsgAfterDidLinkFun];
- }
- break;
- case RTCDataChannelStateClosing:
- {
-
- }
- break;
- case RTCDataChannelStateClosed:
- {
- //链接断开
- [self relinkWebRtcFun];
- }
- break;
- default:
- break;
- }
- }
- -(void)onChannelDataFromPeerName:(NSString*)peerName buffer:(RTC_OBJC_TYPE(RTCDataBuffer) *)buffer
- {
- //HLog(@"onIceConnectedFromPeerName:%@",buffer.data);
- if(buffer && buffer.data){
- KWeakSelf
- mainBlock(^{
- [weakSelf handleWebRtcMsgResponseBy:buffer.data];
- });
- }
- }
- -(void)onIceConnectedFromPeerName:(NSString*)peerName{
- HLog(@"onIceConnectedFromPeerName:%@",peerName);
- }
- -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
- {
- //HLog(@"didGetStats:%@",stats)
- if(!_needToReportWebRtcType){
- [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats];
- _needToReportWebRtcType = YES;
- [_mediaStream setShouldGetStats:NO];
- }
- }
- -(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
- {
- HLog(@"onAuthResultFromPeerName")
- }
- @end
|