| | |
| | | //// |
| | | //// EZVideoTalkViewcontroller.m |
| | | //// EZBAVDemo |
| | | //// |
| | | //// Created by kanhaiping on 2018/6/26. |
| | | //// Copyright © 2018年 hikvision. All rights reserved. |
| | | //// |
| | | // |
| | | // EZVideoTalkViewcontroller.m |
| | | // EZBAVDemo |
| | | //#import "EZVideoTalkViewcontroller.h" |
| | | //#import "EZVideoTalkSDK.h" |
| | | //#import "EZVideoTalkParam.h" |
| | | //#import "UIView+Toast.h" |
| | | //#import <AVFoundation/AVFoundation.h> |
| | | //#import "EZOpenSDK.h" |
| | | //#import "EZDeviceInfo.h" |
| | | //#import "GlobalKit.h" |
| | | //#import "EzvizWatchServerInfo.h" |
| | | //#import "EZTokenKit.h" |
| | | // |
| | | // Created by kanhaiping on 2018/6/26. |
| | | // Copyright © 2018年 hikvision. All rights reserved. |
| | | //@interface EZVideoTalkViewcontroller ()<EZVideoTalkSDKDelegate> |
| | | //@property (nonatomic, assign) BOOL bEverOpenSound; |
| | | //@property (nonatomic, strong) EZVideoTalkSDK *client; |
| | | // |
| | | |
| | | #import "EZVideoTalkViewcontroller.h" |
| | | #import "EZVideoTalkSDK.h" |
| | | #import "EZVideoTalkParam.h" |
| | | #import "UIView+Toast.h" |
| | | #import <AVFoundation/AVFoundation.h> |
| | | #import "EZOpenSDK.h" |
| | | #import "EZDeviceInfo.h" |
| | | #import "GlobalKit.h" |
| | | #import "EzvizWatchServerInfo.h" |
| | | #import "EZTokenKit.h" |
| | | |
| | | @interface EZVideoTalkViewcontroller ()<EZVideoTalkSDKDelegate> |
| | | @property (nonatomic, assign) BOOL bEverOpenSound; |
| | | @property (nonatomic, strong) EZVideoTalkSDK *client; |
| | | |
| | | @property (weak, nonatomic) IBOutlet UIView *localView; |
| | | @property (weak, nonatomic) IBOutlet UIView *remoteView; |
| | | @property (weak, nonatomic) IBOutlet UITextField *roomIDTextField; |
| | | |
| | | @property (nonatomic, strong) EzvizWatchServerInfo *watchServerInfo; |
| | | |
| | | @end |
| | | |
| | | @implementation EZVideoTalkViewcontroller |
| | | |
| | | + (EZVideoTalkViewcontroller *) videoTalkVC { |
| | | |
| | | EZVideoTalkViewcontroller *vc = [[NSBundle mainBundle] loadNibNamed:@"EZVideoTalkViewcontroller" owner:nil options:nil].firstObject; |
| | | return vc; |
| | | } |
| | | |
| | | - (void)viewDidLoad { |
| | | [super viewDidLoad]; |
| | | // Do any additional setup after loading the view, typically from a nib. |
| | | UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; |
| | | if (self.view.gestureRecognizers.count <= 0) { |
| | | [self.view addGestureRecognizer:gesture]; |
| | | } |
| | | |
| | | self.title = @"Video Talk"; |
| | | } |
| | | |
| | | - (void)viewWillAppear:(BOOL)animated { |
| | | [super viewWillAppear:animated]; |
| | | |
| | | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(stopTalk) name:UIApplicationDidEnterBackgroundNotification object:nil]; |
| | | [self getWatchInfo]; |
| | | } |
| | | |
| | | - (void)viewWillDisappear:(BOOL)animated { |
| | | [super viewWillDisappear:animated]; |
| | | |
| | | [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| | | |
| | | if (self.client != nil) { |
| | | [self stopTalk]; |
| | | } |
| | | } |
| | | |
| | | - (void)didReceiveMemoryWarning { |
| | | [super didReceiveMemoryWarning]; |
| | | // Dispose of any resources that can be recreated. |
| | | } |
| | | |
| | | |
| | | #pragma mark Actions |
| | | |
| | | - (IBAction)createRoomAction:(id)sender { |
| | | |
| | | [self startTalkWithRoomID:0]; |
| | | } |
| | | |
| | | - (IBAction)enterRoomAction:(id)sender { |
| | | |
| | | if (self.roomIDTextField.text.length <= 0 || [self.roomIDTextField.text integerValue] <= 0) { |
| | | [self showMessage:@"请输入正确的房间号"]; |
| | | return; |
| | | } |
| | | |
| | | [self startTalkWithRoomID:(int32_t)[self.roomIDTextField.text integerValue]]; |
| | | |
| | | [self showMessage:@"加入房间"]; |
| | | } |
| | | |
| | | - (IBAction)leaveRoomAction:(id)sender { |
| | | |
| | | [self stopTalk]; |
| | | |
| | | [self showMessage:@"已离开房间"]; |
| | | } |
| | | |
| | | - (void)tapAction:(id)sender { |
| | | |
| | | [self.roomIDTextField resignFirstResponder]; |
| | | } |
| | | |
| | | #pragma mark Helper |
| | | |
| | | - (void)showMessage:(NSString *)message |
| | | { |
| | | [self.view makeToast:message duration:2.0 position:CSToastPositionCenter]; |
| | | } |
| | | |
| | | #pragma mark BAV API |
| | | |
| | | - (void)getWatchInfo { |
| | | |
| | | __weak typeof(self) weakSelf = self; |
| | | [EZOpenSDK requestGetWatchServerInfo:self.deviceInfo.deviceSerial completion:^(id watchServerInfo, NSError *error) { |
| | | |
| | | weakSelf.watchServerInfo = watchServerInfo; |
| | | }]; |
| | | } |
| | | |
| | | - (void)startTalkWithRoomID:(int32_t)roomID |
| | | { |
| | | if (self.client != nil) { |
| | | [self.client stop]; |
| | | self.client = nil; |
| | | } |
| | | |
| | | EZVideoTalkParam *param = [EZVideoTalkParam new]; |
| | | param.iCltRole = roomID > 0 ? 1 : 0; |
| | | param.iCltType = 1; |
| | | param.iOtherCltType = 1; |
| | | // param.iReason = 101; |
| | | param.iStsPort = self.watchServerInfo.port; |
| | | param.iRoomId = roomID > 0 ? roomID : 0; |
| | | param.szOterId = self.deviceInfo.deviceSerial; |
| | | param.szSelfId = @"1234567891"; |
| | | param.szAuthToken = [EZTokenKit sharedKit].token; |
| | | param.szStsAddr = self.watchServerInfo.domain; |
| | | |
| | | [EZVideoTalkSDK setDebugVideoLog:YES]; |
| | | [EZVideoTalkSDK setDebugLogEnable:YES withLogCallback:^(NSString *logStr) { |
| | | NSLog(@"%@", logStr); |
| | | }]; |
| | | |
| | | _client = [[EZVideoTalkSDK alloc] initWithParam:param localWindow:self.localView remoteWindow:self.remoteView]; |
| | | _client.delegate = self; |
| | | |
| | | // [_client startWithType:EZVideoTalkCaptureVideo | EZVideoTalkCaptureAudio]; |
| | | [_client startWithType:EZVideoTalkCaptureAudio]; |
| | | } |
| | | |
| | | - (void)stopTalk |
| | | { |
| | | [self.client stop]; |
| | | self.client = nil; |
| | | } |
| | | |
| | | #pragma mark EZVideoTalkSDKDelegate |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client didReceivedError:(int32_t)errorCode |
| | | { |
| | | NSLog(@"%s recived errorcode:%d", __func__, errorCode); |
| | | |
| | | dispatch_async(dispatch_get_main_queue(), ^{ |
| | | [self showMessage:[NSString stringWithFormat:@"BAVClient Error:%d",errorCode]]; |
| | | }); |
| | | |
| | | [self stopTalk]; |
| | | } |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client didReceivedMessage:(EZVideoTalkMessageType)messageCode msg:(NSString *)msg |
| | | { |
| | | NSLog(@"%s recived messagecode:%lu ,msg:%@", __func__, (unsigned long)messageCode, msg); |
| | | |
| | | dispatch_async(dispatch_get_main_queue(), ^{ |
| | | |
| | | if (messageCode == EZVideoTalkMessageRoomCreated) { |
| | | |
| | | [self showMessage:[NSString stringWithFormat:@"已创建房间:%d", self.client.roomID]]; |
| | | self.roomIDTextField.text = [NSString stringWithFormat:@"%d", self.client.roomID]; |
| | | } |
| | | else if (messageCode == EZVideoTalkMessageStartInputData) { |
| | | |
| | | [self showMessage:[NSString stringWithFormat:@"开始推流"]]; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client didReceivedBavClientLogMsg:(NSString *)msg { |
| | | |
| | | NSLog(@"%s recived msg:%@", __func__, msg); |
| | | } |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client playDelayTime:(int32_t)delayTime { |
| | | |
| | | NSLog(@"%s delayTime:%d", __func__, delayTime); |
| | | |
| | | dispatch_async(dispatch_get_main_queue(), ^{ |
| | | [self showMessage:[NSString stringWithFormat:@"播放卡顿-delayTime:%d", delayTime]]; |
| | | }); |
| | | } |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client playDelayTimeStatistics:(double)delayTimeStat { |
| | | |
| | | NSLog(@"%s delayTimeStat:%f", __func__, delayTimeStat); |
| | | } |
| | | |
| | | - (void)videoTalk:(EZVideoTalkSDK *)client didDisplayWidth:(int32_t)width height:(int32_t)height { |
| | | |
| | | NSLog(@"%s", __func__); |
| | | if (!self.bEverOpenSound) { |
| | | self.bEverOpenSound = YES; |
| | | [self.client openSound:YES]; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @end |
| | | //@property (weak, nonatomic) IBOutlet UIView *localView; |
| | | //@property (weak, nonatomic) IBOutlet UIView *remoteView; |
| | | //@property (weak, nonatomic) IBOutlet UITextField *roomIDTextField; |
| | | // |
| | | //@property (nonatomic, strong) EzvizWatchServerInfo *watchServerInfo; |
| | | // |
| | | //@end |
| | | // |
| | | //@implementation EZVideoTalkViewcontroller |
| | | // |
| | | //+ (EZVideoTalkViewcontroller *) videoTalkVC { |
| | | // |
| | | // EZVideoTalkViewcontroller *vc = [[NSBundle mainBundle] loadNibNamed:@"EZVideoTalkViewcontroller" owner:nil options:nil].firstObject; |
| | | // return vc; |
| | | //} |
| | | // |
| | | //- (void)viewDidLoad { |
| | | // [super viewDidLoad]; |
| | | // // Do any additional setup after loading the view, typically from a nib. |
| | | // UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; |
| | | // if (self.view.gestureRecognizers.count <= 0) { |
| | | // [self.view addGestureRecognizer:gesture]; |
| | | // } |
| | | // |
| | | // self.title = @"Video Talk"; |
| | | //} |
| | | // |
| | | //- (void)viewWillAppear:(BOOL)animated { |
| | | // [super viewWillAppear:animated]; |
| | | // |
| | | // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(stopTalk) name:UIApplicationDidEnterBackgroundNotification object:nil]; |
| | | // [self getWatchInfo]; |
| | | //} |
| | | // |
| | | //- (void)viewWillDisappear:(BOOL)animated { |
| | | // [super viewWillDisappear:animated]; |
| | | // |
| | | // [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| | | // |
| | | // if (self.client != nil) { |
| | | // [self stopTalk]; |
| | | // } |
| | | //} |
| | | // |
| | | //- (void)didReceiveMemoryWarning { |
| | | // [super didReceiveMemoryWarning]; |
| | | // // Dispose of any resources that can be recreated. |
| | | //} |
| | | // |
| | | // |
| | | //#pragma mark Actions |
| | | // |
| | | //- (IBAction)createRoomAction:(id)sender { |
| | | // |
| | | // [self startTalkWithRoomID:0]; |
| | | //} |
| | | // |
| | | //- (IBAction)enterRoomAction:(id)sender { |
| | | // |
| | | // if (self.roomIDTextField.text.length <= 0 || [self.roomIDTextField.text integerValue] <= 0) { |
| | | // [self showMessage:@"请输入正确的房间号"]; |
| | | // return; |
| | | // } |
| | | // |
| | | // [self startTalkWithRoomID:(int32_t)[self.roomIDTextField.text integerValue]]; |
| | | // |
| | | // [self showMessage:@"加入房间"]; |
| | | //} |
| | | // |
| | | //- (IBAction)leaveRoomAction:(id)sender { |
| | | // |
| | | // [self stopTalk]; |
| | | // |
| | | // [self showMessage:@"已离开房间"]; |
| | | //} |
| | | // |
| | | //- (void)tapAction:(id)sender { |
| | | // |
| | | // [self.roomIDTextField resignFirstResponder]; |
| | | //} |
| | | // |
| | | //#pragma mark Helper |
| | | // |
| | | //- (void)showMessage:(NSString *)message |
| | | //{ |
| | | // [self.view makeToast:message duration:2.0 position:CSToastPositionCenter]; |
| | | //} |
| | | // |
| | | //#pragma mark BAV API |
| | | // |
| | | //- (void)getWatchInfo { |
| | | // |
| | | // __weak typeof(self) weakSelf = self; |
| | | // [EZOpenSDK requestGetWatchServerInfo:self.deviceInfo.deviceSerial completion:^(id watchServerInfo, NSError *error) { |
| | | // |
| | | // weakSelf.watchServerInfo = watchServerInfo; |
| | | // }]; |
| | | //} |
| | | // |
| | | //- (void)startTalkWithRoomID:(int32_t)roomID |
| | | //{ |
| | | // if (self.client != nil) { |
| | | // [self.client stop]; |
| | | // self.client = nil; |
| | | // } |
| | | // |
| | | // EZVideoTalkParam *param = [EZVideoTalkParam new]; |
| | | // param.iCltRole = roomID > 0 ? 1 : 0; |
| | | // param.iCltType = 1; |
| | | // param.iOtherCltType = 1; |
| | | //// param.iReason = 101; |
| | | // param.iStsPort = self.watchServerInfo.port; |
| | | // param.iRoomId = roomID > 0 ? roomID : 0; |
| | | // param.szOterId = self.deviceInfo.deviceSerial; |
| | | // param.szSelfId = @"1234567891"; |
| | | // param.szAuthToken = [EZTokenKit sharedKit].token; |
| | | // param.szStsAddr = self.watchServerInfo.domain; |
| | | // |
| | | // [EZVideoTalkSDK setDebugVideoLog:YES]; |
| | | // [EZVideoTalkSDK setDebugLogEnable:YES withLogCallback:^(NSString *logStr) { |
| | | // NSLog(@"%@", logStr); |
| | | // }]; |
| | | // |
| | | // _client = [[EZVideoTalkSDK alloc] initWithParam:param localWindow:self.localView remoteWindow:self.remoteView]; |
| | | // _client.delegate = self; |
| | | // |
| | | // // [_client startWithType:EZVideoTalkCaptureVideo | EZVideoTalkCaptureAudio]; |
| | | // [_client startWithType:EZVideoTalkCaptureAudio]; |
| | | //} |
| | | // |
| | | //- (void)stopTalk |
| | | //{ |
| | | // [self.client stop]; |
| | | // self.client = nil; |
| | | //} |
| | | // |
| | | //#pragma mark EZVideoTalkSDKDelegate |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client didReceivedError:(int32_t)errorCode |
| | | //{ |
| | | // NSLog(@"%s recived errorcode:%d", __func__, errorCode); |
| | | // |
| | | // dispatch_async(dispatch_get_main_queue(), ^{ |
| | | // [self showMessage:[NSString stringWithFormat:@"BAVClient Error:%d",errorCode]]; |
| | | // }); |
| | | // |
| | | // [self stopTalk]; |
| | | //} |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client didReceivedMessage:(EZVideoTalkMessageType)messageCode msg:(NSString *)msg |
| | | //{ |
| | | // NSLog(@"%s recived messagecode:%lu ,msg:%@", __func__, (unsigned long)messageCode, msg); |
| | | // |
| | | // dispatch_async(dispatch_get_main_queue(), ^{ |
| | | // |
| | | // if (messageCode == EZVideoTalkMessageRoomCreated) { |
| | | // |
| | | // [self showMessage:[NSString stringWithFormat:@"已创建房间:%d", self.client.roomID]]; |
| | | // self.roomIDTextField.text = [NSString stringWithFormat:@"%d", self.client.roomID]; |
| | | // } |
| | | // else if (messageCode == EZVideoTalkMessageStartInputData) { |
| | | // |
| | | // [self showMessage:[NSString stringWithFormat:@"开始推流"]]; |
| | | // } |
| | | // }); |
| | | //} |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client didReceivedBavClientLogMsg:(NSString *)msg { |
| | | // |
| | | // NSLog(@"%s recived msg:%@", __func__, msg); |
| | | //} |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client playDelayTime:(int32_t)delayTime { |
| | | // |
| | | // NSLog(@"%s delayTime:%d", __func__, delayTime); |
| | | // |
| | | // dispatch_async(dispatch_get_main_queue(), ^{ |
| | | // [self showMessage:[NSString stringWithFormat:@"播放卡顿-delayTime:%d", delayTime]]; |
| | | // }); |
| | | //} |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client playDelayTimeStatistics:(double)delayTimeStat { |
| | | // |
| | | // NSLog(@"%s delayTimeStat:%f", __func__, delayTimeStat); |
| | | //} |
| | | // |
| | | //- (void)videoTalk:(EZVideoTalkSDK *)client didDisplayWidth:(int32_t)width height:(int32_t)height { |
| | | // |
| | | // NSLog(@"%s", __func__); |
| | | // if (!self.bEverOpenSound) { |
| | | // self.bEverOpenSound = YES; |
| | | // [self.client openSound:YES]; |
| | | // } |
| | | //} |
| | | // |
| | | // |
| | | // |
| | | //@end |