CallKit:No sound when I use WebRTC

寵の児 提交于 2019-12-10 14:57:09

问题


Our project uses WebRTC for VOIP calls and it works fine before accessing the CallKit framework. But when I tried to access the CallKit framework, there was a situation where neither side could hear each other's speech. When I removed CallKit, everything returned to normal.

CallKit's answer button is the same function as the original answer button in the project.

And what amazed me was that it was not necessary to hear no sound. Sometimes everything is normal, but sometimes there will be problems. Well, the probability of a problem is greater.

I found the following flowchart, I suspect the problem lies in the order of function calls. But I do not know how WebRTC corresponds to the functions in the diagram.

In addition, I am curious whether socket instability will cause the CallKit framework to work abnormally

Please forgive me English is not good, but this problem has been haunted me for several days, I do not know where exactly a problem, is not where the conflict with the CallKit framework?

Hope you can help me, thank you very much!


回答1:


In the end, I solved the problem, but I still do not understand why it can be solved.Below is my solution:

First of all, I delay the call of "fulfill" by 1 second (note that this time can not be less than 1 second)

- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action {

if (self.delegate && [self.delegate respondsToSelector:@selector(callKitManager:refreshCurrentCallStatus:)]) {
    [self.delegate callKitManager:self refreshCurrentCallStatus:EUCCallKitStatusAnswerAccept];
}

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [action fulfill];
});}

Second, I also delayed my network request call by one second (here longer than the previous one)

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  [self.peerConnection offerForConstraints:[self offerConstraintsRestartIce:NO] completionHandler:^(RTCSessionDescription * _Nullable sdp, NSError * _Nullable error) {

  [self peerConnection:self.peerConnection didCreateSessionDescription:sdp error:error];
        }];

});

In this way, my problem is solved.

If you know why this can solve this problem, please comment on me, thank you!




回答2:


Few steps need to be done to connect webrtc and callkit in proper way: First of all, you have to use the RTCAudioTrack and add the RTCAudioSession for handling the audio. Old legacy RTCAudioSession added directly into RTCPeerConnection works but it's not prefered a way to do that. Second thing is to use manualAudio. When app is booted you should change useManualAudio flag on RTCAudioSession:

RTCAudioSession.sharedSession().useManaulAudio = true

which gives you possibility to postpone the audio until CallKit informs that audio session was activated, so inside the ProviderDelegate you should implement following method:

(void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession
RTCAudioSession.sharedSession().didActivecated(audioSession)
RTCAudioSession.sharedSession().isAudioEnabled = true

and for second audio delegate method don't forget to add:

(void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSession *)audioSession
RTCAudioSession.sharedSession().didDeactivecated(audioSession)
RTCAudioSession.sharedSession().isAudioEnabled = false


来源:https://stackoverflow.com/questions/48070163/callkitno-sound-when-i-use-webrtc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!