美文网首页
Linphone SDK使用(三)电话功能

Linphone SDK使用(三)电话功能

作者: fanren | 来源:发表于2023-04-12 10:11 被阅读0次

一、监听电话

监听电话的拨出与电话的接收;

[NSNotificationCenter.defaultCenter addObserver:self
                                           selector:@selector(respondsToCallUpdate:)
                                               name:kLinphoneCallUpdate
                                             object:nil];
- (void)respondsToCallUpdate:(NSNotification *)notif
{
    LinphoneCall *call = [[notif.userInfo objectForKey:@"call"] pointerValue];
    LinphoneCallState state = [[notif.userInfo objectForKey:@"state"] intValue];
    NSString *message = [notif.userInfo objectForKey:@"message"];
    NSLog(@"----------state----------%ld", state);
    switch (state) {
        case LinphoneCallIncomingReceived:
        {
            [self displayIncomingCall:call];
//            if (!CallManager.callKitEnabled) {
//                [self displayIncomingCall:call];
//            }
        }
            break;
        case LinphoneCallIncomingEarlyMedia:
        {
            if (linphone_core_get_calls_nb(LC) > 1 ||
                (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max)) {
                [self displayIncomingCall:call];
            }
            break;
        }
        case LinphoneCallOutgoingInit:
        case LinphoneCallOutgoingEarlyMedia:
        case LinphoneCallOutgoingProgress:
        case LinphoneCallOutgoingRinging:
        {
            CallAppData *data = [CallManager getAppDataWithCall:call];
            if (!data.isConference) {
                // 如果不是会议,则跳转到播出电话页面
                [self displayOutgointCall:call];
            }
            break;
        }
        case LinphoneCallPausedByRemote:
        case LinphoneCallConnected:
        {
            if (![LinphoneManager.instance isCTCallCenterExist]) {
                /*only register CT call center CB for connected call*/
                [LinphoneManager.instance setupGSMInteraction];
            }
            break;
        }
        case LinphoneCallError: {
            [self displayCallError:call message:message];
        }
        case LinphoneCallEarlyUpdatedByRemote:
        case LinphoneCallEarlyUpdating:
        case LinphoneCallIdle:
            break;
        case LinphoneCallReleased:
        {
            self.ingoingInfo = nil;
            if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self showCallVC];
                    [CallManager.instance stopLinphoneCore];
                    // 退回到拨号页面
                });
            }
        }
            break;
        case LinphoneCallPaused:
        case LinphoneCallPausing:
        case LinphoneCallRefered:
            break;
        case LinphoneCallResuming: {
            break;
        }
        case LinphoneCallStateStreamsRunning: {
            [self configureAudioSession];
        }
            break;
        case LinphoneCallUpdating:
            break;
    }
}

二、拨打电话

LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:number];
[[LinphoneManager instance] call:addr];
self.callNumber = number;
if (addr) {
    linphone_address_destroy(addr);
}

三、接听电话

[CallManager.instance acceptCallWithCall:call hasVideo:YES]

这里的CallManager是取自官方demo中关于音频通话部分的代码;

四、取消接听电话

[CallManager.instance terminateCallWithCall:call];

相关文章

网友评论

      本文标题:Linphone SDK使用(三)电话功能

      本文链接:https://www.haomeiwen.com/subject/xbggddtx.html