From bf7f42bc3b63a0c2cec5a5adfb44feffab47a077 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 01 四月 2021 15:08:55 +0800
Subject: [PATCH] 2021-04-01 1.更新

---
 SDKDemo/ESVideoPhoneSDKDemo_F20210315/ESVideoPhoneSDKDemo/ViewController.mm |  141 +++++++++++++++++++++++++++++++---------------
 1 files changed, 95 insertions(+), 46 deletions(-)

diff --git a/ESVideoPhoneSDKDemo1.2/ESVideoPhoneSDKDemo/ESVideoPhoneSDKDemo/ViewController.mm b/SDKDemo/ESVideoPhoneSDKDemo_F20210315/ESVideoPhoneSDKDemo/ViewController.mm
similarity index 85%
rename from ESVideoPhoneSDKDemo1.2/ESVideoPhoneSDKDemo/ESVideoPhoneSDKDemo/ViewController.mm
rename to SDKDemo/ESVideoPhoneSDKDemo_F20210315/ESVideoPhoneSDKDemo/ViewController.mm
index eadb201..d5296ba 100644
--- a/ESVideoPhoneSDKDemo1.2/ESVideoPhoneSDKDemo/ESVideoPhoneSDKDemo/ViewController.mm
+++ b/SDKDemo/ESVideoPhoneSDKDemo_F20210315/ESVideoPhoneSDKDemo/ViewController.mm
@@ -16,16 +16,15 @@
  娣诲姞绯荤粺搴� libiconv2.4.0.tbd,libz.tbd,libbz2.tbd.
  3銆乨emo浠呭仛鍙傝�冿紝鍏蜂綋璇锋牴鎹瓵pp鐨勬儏鍐甸�傛椂璋冪敤
  */
+#import <ifaddrs.h>
+#import <arpa/inet.h>
 #import <AVFoundation/AVFoundation.h>
 #import "ViewController.h"
 #import <ESVideoPhoneSDk/ESVideoPhone.h>
 #import <ESVideoPhoneSDk/ESError.h>
-#import "AudioSessionHelper.h"
-#import "ESVideo.h"
 
 @interface ViewController ()<ESVideoPhoneDelegate,UITextFieldDelegate>
 
-@property (nonatomic,strong) AudioSessionHelper    *sessionHelper;
 @property (nonatomic,strong) ESVideoPhone          *es;
 @property (nonatomic,assign) BOOL                  playing;
 @property (nonatomic,assign) BOOL                  isInterrupt;
@@ -35,38 +34,32 @@
 @property (weak, nonatomic) IBOutlet UITextField *uIDTextField;
 @property (weak, nonatomic) IBOutlet UIButton *mCallOrAccept;
 @property (weak, nonatomic) IBOutlet UIButton *monitorBtn;
+@property (weak, nonatomic) IBOutlet UITextField *mngUUIDTextField;
 
 @end
 
 @implementation ViewController
 {
+
     BOOL isAccessAudio;
     BOOL isAccessVideo;
     BOOL isBackGround;
     BOOL iSVideoNotDetermined;
     BOOL iSAudioNotDetermined;
-    
-    
 }
 - (void)viewDidLoad {
     [super viewDidLoad];
-    [ESVideo.shareInstance initSDK];
+    [self testHttp];
     //鍒濆鍖栦腑鏂紝杩涘叆鍚庡彴鐨則ag
     _playing = NO;
-    _isSpeaking = NO;
+    _isSpeaking = YES;
     self.isInterrupt = NO;
-    _es = ESVideo.shareInstance.es;
     _es.isInterrupt = NO;
     isBackGround = NO;
     [_speakerBtn setTitle:@"鍚瓛" forState:UIControlStateNormal];
 //    _mCallOrAccept.enabled = NO;
 //    _monitorBtn.enabled = NO;
-//    _uIDTextField.text = @"JJY000016YWECG";//@"JJY000007FSEYX" 榛樿闂ㄥ彛鏈虹殑ID
-//       _uIDTextField.text = @"JJY000017XLUXX";//@"JJY000007FSEYX" 榛樿闂ㄥ彛鏈虹殑ID
-    _uIDTextField.text = @"JJY000019VPLLF";//@"JJY000019VPLLF" 榛樿闂ㄥ彛鏈虹殑ID
-    
-//           _uIDTextField.text = @"JJY000016YWECG";//@"JJY000016YWECG" 榛樿闂ㄥ彛鏈虹殑ID
-    
+    _uIDTextField.text = @"JJY000019VPLLF"; //@"JJY000016YWECG";//@"JJY000007FSEYX" 榛樿闂ㄥ彛鏈虹殑ID
     _uIDTextField.delegate = self;    //鈿狅笍杩欓噷蹇呴』瑕佹鏌ユ槸鍚﹀凡缁忔巿鏉冨惁鍒欎細澶辫触锛屽垵濮嬪寲瑙嗛闊抽閲囬泦
     [self requestAccessForAVMediaType:AVMediaTypeAudio];
      if (isAccessAudio) {
@@ -77,21 +70,16 @@
                  [self saveImage:image];
              });
          };
-         //闂ㄥ彛鏈轰細鏈夎棰戠殑闀垮楂橈紝鏄浐瀹氱殑锛堟殏鏃惰繕涓嶇‘瀹氾級
-//         _es = [[ESVideoPhone alloc]initESVideoPhoneWithFrame:CGRectMake(10, 100, self.view.frame.size.width-20, (self.view.frame.size.width-20)/4*3) delegate:self imagecallBack:snapImageCallback];
+         //闂ㄥ彛鏈轰細鏈夎棰戠殑闀垮楂橈紝鏄浐瀹氱殑锛堟殏鏃惰繕涓嶇‘瀹氾級锛�
+         _es = [[ESVideoPhone alloc]initESVideoPhoneWithFrame:CGRectMake(10, 100, self.view.frame.size.width-20, (self.view.frame.size.width-20)/4*3) delegate:self imagecallBack:snapImageCallback];
          if (_es) {
              //鍒ゆ柇瑙嗛娓叉煋鏄惁鍒濆鍖栨垚鍔燂紝濡傛灉澶辫触浼氳蛋ESVideoPhoneDelegate鏂规硶
              if (_es.showView) {
-//                 _es.showView.frame = CGRectMake(10, 100, self.view.frame.size.width-20, (self.view.frame.size.width-20)/4*3);
-                 ESVideo.shareInstance.snapImageCallback = snapImageCallback;
-                 _es.showView.backgroundColor = [UIColor greenColor];
                  _es.delegate = self;
                  [self.view addSubview:_es.showView];
-             }else{
-                 NSLog(@"_es.showView null");
-                 
              }
          }else{
+             //p2p鍒濆鍖栧け璐ヤ細杩斿洖nil
              NSLog(@"ESVideoPhone 鍒濆鍖栧け璐�");
              return;
          }
@@ -110,14 +98,46 @@
             NSLog(@"VideoCaptureSession 鍒濆鍖栧け璐�");
         }
     }
-    //鍒濆鍖朅udioSession
-    _sessionHelper = [[AudioSessionHelper alloc]init];
-    [_sessionHelper setAudioSession];
     //娣诲姞杩涘叆鍚庡彴锛屼腑鏂瓑閫氱煡
     [self addObservers];
+    [self internetStatus];
+    
+    
+    NSLog(@"%@", [self getIpAddress]);
 }
 
+-(void)internetStatus {
+    
+    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];//姝ゅ淇敼涓鸿嚜宸卞叕鍙哥殑鏈嶅姟鍣ㄥ湴鍧�
+        NSURLRequest *request = [NSURLRequest requestWithURL:url];
+        NSURLSession *session = [NSURLSession sharedSession];
+        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
+            if (error == nil) {
+                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
+                NSLog(@"%@",dict);
+            }
+        }];
+        
+        [dataTask resume];
+}
+-(void)testHttp
+{
+    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];//姝ゅ淇敼涓鸿嚜宸卞叕鍙哥殑鏈嶅姟鍣ㄥ湴鍧�
+    NSURLRequest *request = [NSURLRequest requestWithURL:url];
+    NSURLSession *session = [NSURLSession sharedSession];
+    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
+        if (error == nil) {
+            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
+            NSLog(@"缃戠粶璇锋眰娴嬭瘯%@",dict);
+        }else{
+            NSLog(@"缃戠粶璇锋眰娴嬭瘯澶辫触");
+        }
+    }];
+    
+    [dataTask resume];
+}
 -(void)viewDidAppear:(BOOL)animated{
+    [super viewDidAppear:animated];
     //杩欎釜鏂规硶璇锋牴鎹瓵pp鐨勫叿浣撴儏鍐佃皟鐢�
     //鍦╲iewDidLoad涓� 璋冪敤requestAccessForAVMediaType: 鏄负浜嗚妭绾﹀垵濮嬪寲鐨勬椂闂�
     //鍦╲iewDidAppear涓皟鐢╮equestAccessForAVMediaType: 鏄负浜嗗脊鍑烘彁绀烘墦寮�鏉冮檺鐨凙lert
@@ -138,61 +158,64 @@
     [_es stopTalk];
 }
 -(void)dealloc{
-    _es.delegate = nil;
-//    _es.showView
-      NSLog(@"==============dealloc1");
     [[NSNotificationCenter defaultCenter] removeObserver:self];
-      NSLog(@"==============dealloc2");
-//    [_es freeSubClass];
-      NSLog(@"==============dealloc3");
+    [_es freeSubClass];
 }
 
 #pragma mark ButtonAction
-- (IBAction)back:(id)sender {
-    [self dismissViewControllerAnimated:YES completion:NULL];
-       
-}
 //鍙嶅懠锛氭ā鎷熼棬鍙f満鍛煎彨鎵嬫満锛岄渶瑕侀棬鍙f満鍏堢偣鍛煎彨锛岀瓑1-2S鍚庯紝鎵嬫満鐐瑰弽鍛笺��
-//params鏍锋湰 address=192.168.1.3:8554,tag=mobile://123,
+//params鏍锋湰 address=JJY000003UYRBK,tag=mobile://123,
 - (IBAction)onReverseCall:(id)sender {
     NSString *title = [sender titleForState:UIControlStateNormal];
     if ([title isEqualToString:@"鍙嶅懠"]) {
        NSString *normalStr = _uIDTextField.text;
        NSString *param = [NSString stringWithFormat:@"address=%@,tag=mobile://123,",normalStr];
-       NSLog(@"============鐐瑰弽鍛�%@", param);
+       //NSLog(@"%@", param);
        [_es onReverseCall:param];
     }else if([title isEqualToString:@"鎺ュ惉"]){
-        [_es onAccept];
+       [_es onAccept];
     }
   
 }
+
 - (IBAction)onHangup:(id)sender {
     [_es onHangup];
 }
+
+
+- (IBAction)onCallMng:(UIButton *)sender {
+    
+    [_es onCall:_mngUUIDTextField.text];
+}
+
 - (IBAction)onMonitor:(id)sender {
     [_es onMonitor:_uIDTextField.text];
 }
 - (IBAction)speaker:(UIButton *)sender {
-    [_es stopTalk];
-      
       NSString *result = nil;
       //鍚瓛鐘舵�� 鎻掕�冲鍚庢嫈鎺夊悗鎭㈠鍒伴粯璁よ缃�
       if (sender == nil) {
-          result = [_sessionHelper speaker:NO];
+          //result = [_sessionHelper speaker:YES];
+          if ([_es resetAudioCaptureIsSpeak:YES]) {
+              result = @"鍚瓛";
+          }
       }else{
           if(!_isSpeaking){
-              result = [_sessionHelper speaker:YES];
+            //  result = [_sessionHelper speaker:YES];
+              [_es resetAudioCaptureIsSpeak:YES];
+              result = @"鍚瓛";
               _isSpeaking = YES;
           }else{
-              result = [_sessionHelper speaker:NO];
+             // result = [_sessionHelper speaker:NO];
+              [_es resetAudioCaptureIsSpeak:NO];
+              result = @"鍏嶆彁";
               _isSpeaking = NO;
           }
       }
       if (result) {
           [sender setTitle:result forState:UIControlStateNormal];
-          [_es startTalk];
       }
-      
+   
 }
 
 - (IBAction)openDoor:(id)sender {
@@ -279,7 +302,7 @@
     // If media services were reset, and the last start succeeded, restart the session.
     if (error.code == AVErrorMediaServicesWereReset) {
         [_es onStopCapture];
-        [_es startTalk];
+        [_es stopTalk];
     }
 }
 
@@ -577,4 +600,30 @@
     
 }
 
+-(NSString *)getIpAddress {
+    NSString *address = @"error";
+    struct ifaddrs *interfaces = NULL;
+    struct ifaddrs *temp_addr = NULL;
+    int success = 0;
+    // retrieve the current interfaces - returns 0 on success
+    success = getifaddrs(&interfaces);
+    if (success == 0) {
+        // Loop through linked list of interfaces
+        temp_addr = interfaces;
+        while(temp_addr != NULL) {
+            if(temp_addr->ifa_addr->sa_family == AF_INET) {
+                // Check if interface is en0 which is the wifi connection on the iPhone
+                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
+                    // Get NSString from C String
+                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
+                }
+            }
+            temp_addr = temp_addr->ifa_next;
+        }
+    }
+    // Free memory
+    freeifaddrs(interfaces);
+    return address;
+}
+
 @end

--
Gitblit v1.8.0