464027401@qq.com
2021-09-27 b469805b2d0c9b23ca020cf9356ff137205f856c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
//  HDLLinPhoneSDK.m
//  HDLLinPhoneSDK
//
//  Created by 陈启扬 on 2021/8/3.
//  Copyright © 2021 陈启扬. All rights reserved.
//
 
#import "HDLLinPhoneSDK.h"
#import "HDLLinphoneManager.h"
#import "HDLLinphoneIntercomVC.h"
#import "HDLLinPhoneCommon.h"
#import "HDLLPOnMonitorViewController.h"
 
@interface HDLLinPhoneSDK()
@property (strong, nonatomic) HDLLinphoneIntercomVC* presentingIntercomVC;//当前展示的来点控制器,用于存放正在展示的来点控制器,避免重复弹出界面
@end
 
@implementation HDLLinPhoneSDK
 
+ (instancetype)instance{
     static  HDLLinPhoneSDK *service = nil;
     static dispatch_once_t onceToken;
    
     dispatch_once(&onceToken, ^{
         service = [[HDLLinPhoneSDK alloc] init];
         [NSNotificationCenter.defaultCenter addObserver:service
                                                selector:@selector(registrationUpdate:)
                                                    name:@"LinphoneRegistrationUpdate"
                                                  object:nil];
         [NSNotificationCenter.defaultCenter addObserver:service
                                                selector:@selector(linphoneCallUpdate:)
                                                    name:@"LinphoneCallUpdate"
                                                  object:nil];
 
         
     });
     return service;
}
 
-(void)dealloc{
//    [NSNotificationCenter.defaultCenter remo];
}
 
-(void)login:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain{
    [HDLLinphoneManager.instance login:username password:pwd domain:domain];
}
 
- (void)registrationUpdate:(NSNotification *)notif {
    LinphoneRegistrationState state = [[notif.userInfo objectForKey:@"state"] intValue];
    if (state == LinphoneRegistrationFailed){
        NSLog(@"登录失败");
    }else if (state == LinphoneRegistrationCleared){
        NSLog(@"登录清空");
    } else if (state == LinphoneRegistrationOk) {
        
//        HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init];
//        [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
//            
//        }];
        NSLog(@"登录成功啦");
    }
}
 
-(void)linphoneCallUpdate:(NSNotification *)notif{
//    self.IsAutoJumpCallView=YES;
    NSString *userName=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"userName"]];
   
    LinphoneCallState state = [[notif.userInfo objectForKey:@"state"] intValue];
    if (state == LinphoneCallIncomingReceived) {
        [self.hdlLinphoneCallDelegate onIncomingCall:userName];
        if(self.IsAutoJumpCallView){
 
            
//                    HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init];
////                    vc.CallId=callId;
//                    vc.hasVideo=YES;
//                    vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
//                    vc.modalPresentationStyle = UIModalPresentationFullScreen;
////                    self.IntercomVC=vc;
//                    [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
//
//                    }];
            
            [self gotoHDLLinphoneIntercomVC:nil];
        }
    }
}
 
-(void)initalLinPhone{
    [HDLLinphoneManager.instance initalLinPhonal];
}
 
-(void)callWithUserName:(NSString*)username title:(NSString *)title{
    
    HDLLPOnMonitorViewController *vc=[[HDLLPOnMonitorViewController alloc]init];
//    vc.CallId=callId;
//    vc.hasVideo=YES;
    vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    vc.userName=username;
    vc.titleName=title;
//    self.CallVC=vc;
    [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
        
    }];
    
}
/**
*  跳转呼叫页面
*
*  @param titleName   标题
*/
-(void)gotoHDLLinphoneIntercomVC:(NSString*)titleName{
    
//    NSString *callId=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"callID"]];
//    BOOL hasVideo=(BOOL)[notif.userInfo objectForKey:@"hasVideo"];
//    NSLog(@"顶层视图:%@",[HDLLinPhoneCommon topMostController]);
   
    if ([HDLLinPhoneCommon rootPresentVCContent:[HDLLinphoneIntercomVC class]]||[HDLLinPhoneCommon rootPresentVCContent:[HDLLPOnMonitorViewController class]]) {
        if ([[HDLLinPhoneCommon topMostController] isKindOfClass:[UIAlertController class]]) {
            NSLog(@"顶层视图是视频通话页");
            __weak typeof(self) weakSelf = self;
            
            [[HDLLinPhoneCommon topMostController] dismissViewControllerAnimated:NO completion:^{
                UIViewController *topVC=[HDLLinPhoneCommon topMostController];
                if ([topVC isKindOfClass:[HDLLPOnMonitorViewController class]]) {
                    [topVC dismissViewControllerAnimated:NO completion:^{
                        [weakSelf toLinphoneIntercomVC:titleName];
                    }];
                }else if ([topVC isKindOfClass:[HDLLinphoneIntercomVC class]]) {
                    [topVC dismissViewControllerAnimated:NO completion:^{
                        [weakSelf toLinphoneIntercomVC:titleName];
                    }];
                }
            }];
        }
//        UIViewController *topVC=[HDLLinPhoneCommon topMostController];
//        if ([topVC isKindOfClass:[HDLLinphoneIntercomVC class]]) {
//            [topVC dismissViewControllerAnimated:NO completion:nil];
//        }
        return;
    }
 
    [self toLinphoneIntercomVC:titleName];
    
//    if (self.presentingIntercomVC) {
//        __weak typeof(self) weakSelf = self;
//        [self.presentingIntercomVC dismissViewControllerAnimated:NO completion:^{
//            NSLog(@"页面退出了");
//            weakSelf.presentingIntercomVC=nil;
//            [weakSelf toLinphoneIntercomVC:titleName];
//        }];
//
//        return;
//    }
//    NSLog(@"执行到我了");
//    [self toLinphoneIntercomVC:titleName];
//    HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init];
////    vc.CallId=callId;
//    vc.hasVideo=YES;
//    vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
//    if (titleName) {
//        vc.titleName=titleName;
//    }
//    vc.modalPresentationStyle = UIModalPresentationFullScreen;
//    self.presentingIntercomVC=vc;
//    [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
//
//    }];
}
 
-(void)toLinphoneIntercomVC:(NSString*)titleName{
    HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init];
//    vc.CallId=callId;
    vc.hasVideo=YES;
    vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate;
    if (titleName) {
        vc.titleName=titleName;
    }
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
//    self.presentingIntercomVC=vc;
    [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{
 
    }];
}
 
-(void)logoutAllLinphoneUser{
    [HDLLinphoneManager.instance removeAllAccounts];
}
 
-(void)clearAllConfigs{
    
}
 
-(void)enterBackground{
    [HDLLinphoneManager.instance enterBackgroundMode];
}
 
-(void)becomactive{
    [HDLLinphoneManager.instance becomeActive];
}
 
-(void)willResignActive{
//    [HDLLinphoneManager.instance willResignActive];
}
@end