Skip to content

Watch CallKit events natively to auto-restore WebRTC audio session#9

Draft
Copilot wants to merge 3 commits into
webrtc-127from
copilot/watch-callkit-events
Draft

Watch CallKit events natively to auto-restore WebRTC audio session#9
Copilot wants to merge 3 commits into
webrtc-127from
copilot/watch-callkit-events

Conversation

Copilot AI commented Mar 18, 2026

Copy link
Copy Markdown

When a phone call interrupts a WebRTC session, the iOS audio session is taken over by CallKit/system and WebRTC cannot recover it automatically on release.

Changes

Native CallKit observer (PluginRTCAudioController.swift)

  • import CallKit; class now inherits NSObject and conforms to CXCallObserverDelegate
  • CXCallObserver registered in init() on DispatchQueue.main
  • callObserver(_:callChanged:) tracks active call count:
    • First call connects → RTCAudioSession.sharedInstance().audioSessionDidActivate(AVAudioSession.sharedInstance())
    • Last call ends → audioSessionDidDeactivate + initAudioDevices() + restoreInputOutputAudioDevice()

Covers both regular PSTN calls and CallKit VoIP calls — CXCallObserver observes all device calls.

CallKit framework (plugin.xml)

<framework src="CallKit.framework" />

JS escape-hatch APIs (js/iosrtc.js)

For apps with their own CXProvider that need exact timing control over audio session transitions:

cordova.plugins.iosrtc.audioSessionDidActivate();   // call inside provider(_:didActivate:)
cordova.plugins.iosrtc.audioSessionDidDeactivate(); // call inside provider(_:didDeactivate:)

These forward directly to RTCAudioSession.sharedInstance().audioSessionDidActivate/Deactivate.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 18, 2026 20:22
Co-authored-by: jerry2013 <4749863+jerry2013@users.noreply.github.com>
Co-authored-by: jerry2013 <4749863+jerry2013@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CallKit event listeners for WebRTC session Watch CallKit events natively to auto-restore WebRTC audio session Mar 18, 2026
Copilot AI requested a review from jerry2013 March 18, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants