[iOS] No audio on a call answered from CallKit when configureAudioSession is false

未关闭
#1,652 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
dart, flutter, ios

调研方向

Start by reading the iOS push notification plugin’s CallKit answer handling and its configureAudioSession() implementation, especially provider(_:perform: CXAnswerCallAction) and provider(_:didActivate:). The report identifies the missing recording category when configuration is disabled, but leaves the preferred fix open among several options. Done means an incoming CallKit answer activates audio with configureAudioSession: false while leaving session activation to the app; check existing iOS CallKit and audio session tests, if present.

由索引模型根据 Issue 内容生成。

描述

Summary

stream_video_push_notification either fully manages AVAudioSession for every CallKit call (configureAudioSession: true) or does nothing at all (false). An app that lets WebRTC own the audio session has to pass false. Then a call answered on the CallKit screen gets no audio in either direction: CallKit never activates the audio session, because the category still can't record when the call is answered.

Environment

  • stream_video_flutter / stream_video_push_notification 1.7.2 (git ref 2ec78303dbc6fe8043e104b4cd378d56b2159a4e)
  • iOS 26.6, iPhone 15 Pro (physical device)
  • Ringing call (getOrCreate(ringing: true)), received as a VoIP push (APN provider) and shown by the plugin with CallKit
  • IOSPushConfiguration(configureAudioSession: false, ...)
  • Audio session configured through AudioConfigurationPolicy.custom (playAndRecord / voiceChat, no mixWithOthers)

Steps to reproduce

  1. Set configureAudioSession: false in StreamVideoPushConfiguration.ios.
  2. Put the callee app in the background. No call has been joined yet, so WebRTC hasn't configured AVAudioSession and its category is still the default.
  3. Ring the callee from another device.
  4. Answer on the CallKit screen, then accept and join the call in the app (consumeIncomingCall → accept → join).

Expected

CallKit activates the audio session (provider(_:didActivate:)), and the call has audio both ways.

Actual

  • The call joins and both peer connections reach connected. The remote audio track is received, and the SFU reports the remote participant speaking.
  • provider(_:didActivate:) is never called after the answer, and no ActionCallToggleAudioSession event arrives.
  • Neither side hears anything.

Cause

When the call is answered, the audio session category is still the app's default, which can't record. With configureAudioSession: false, the plugin's configureAudioSession() is a no-op in both provider(_:perform: CXAnswerCallAction) and provider(_:didActivate:). So nothing sets playAndRecord before the answer action is fulfilled, and CallKit doesn't activate the session. Apple expects the app to configure the category before fulfilling CXAnswerCallAction.

Outgoing calls aren't affected: the app joins first, which lets WebRTC configure the session, and only then reports the call to CallKit (startOutgoingCall).

This is confirmed indirectly: an extra CXAnswerCallAction issued later, after WebRTC had set playAndRecord, did trigger didActivate, and audio came up.

Why configureAudioSession: true isn't an option

With true, the plugin applies a fixed configuration to every call, outgoing included, which overrides the one WebRTC applies:

  • options are hard-coded: .allowBluetoothA2DP, .duckOthers, .allowBluetooth (no way to drop ducking or add .allowAirPlay)
  • setPreferredSampleRate(44100) and setPreferredIOBufferDuration(0.005)
  • setActive(true) is called by the plugin, although with CallKit the system is meant to activate the session

In our case this broke the audio route of outgoing calls, for example the CallKit speaker button. So false is the only workable setting, and incoming calls then have no audio.

Workaround

We observe CallKit from the app and set the category as soon as an incoming call starts ringing. We don't activate the session ourselves:

final class IncomingCallAudioSession: NSObject, CXCallObserverDelegate {
    private let callObserver = CXCallObserver()

    override init() {
        super.init()
        callObserver.setDelegate(self, queue: .main)
    }

    func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
        guard !call.isOutgoing, !call.hasConnected, !call.hasEnded else { return }
        let rtc = RTCAudioSession.sharedInstance()
        guard rtc.category != AVAudioSession.Category.playAndRecord.rawValue else { return }
        rtc.lockForConfiguration()
        defer { rtc.unlockForConfiguration() }
        try? rtc.setCategory(
            .playAndRecord,
            mode: .voiceChat,
            options: [.allowBluetoothHFP, .allowBluetoothA2DP, .allowAirPlay]
        )
    }
}

It's created in application(_:didFinishLaunchingWithOptions:). An app launched by a VoIP push may not have a Flutter engine yet when the call rings, so it can't live in a Flutter plugin.

Proposed fix

Any of these would remove the need for the workaround:

  1. Always set a recording category before fulfilling the answer. When configureAudioSession is false, still set playAndRecord (with a configurable mode and options) in CXAnswerCallAction, without setActive, and leave the rest to the app.
  2. Per-direction setting. For example configureAudioSessionForIncoming / configureAudioSessionForOutgoing, so the plugin can configure answered calls only.
  3. Configurable options. Let IOSPushConfiguration take the category options (and skip the sample rate, buffer duration and setActive calls), so configureAudioSession: true can match the app's WebRTC configuration.
  4. Document it. At least note that configureAudioSession: false requires the app to set a recording category before a CallKit answer.

Related plugin behaviour we ran into

Calling setCallConnected on an incoming call that was already answered requests another CXAnswerCallAction (StreamCallKitCallController.connectedCall). That emits a second ActionCallAccept for the same call. It's easy to hit when an app marks every call connected the same way, as you would for outgoing calls. Ignoring incoming calls in connectedCall, or documenting that it's for outgoing calls only, would help.

主要语言
Dart
星标
79
派生
55
平均合并
2 天 12 小时
30 天内合并 PR
142

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

GetStream/stream-video-flutter 的其他 Issue

查看 GetStream/stream-video-flutter 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。