From 1ac081ea0e910cac9fe6b1c5f36e3997ec588798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Braz=CC=87ewicz?= Date: Wed, 8 Jul 2026 09:32:59 +0200 Subject: [PATCH] add onAudioRouteChangeEvent for iOS --- CHANGELOG.md | 6 ++++++ common/darwin/Classes/FlutterWebRTCPlugin.m | 12 ++++++++++++ .../stream_webrtc_flutter/FlutterWebRTCPlugin.m | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be459f3781..bf898edd20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog +[3.0.1] - upcoming + +**New** + +* [iOS] Added an onAudioRouteChangeEvent that fires whenever audio output route changes. + [3.0.0] - 2026-05-14 **Per-call peer connection factory architecture** diff --git a/common/darwin/Classes/FlutterWebRTCPlugin.m b/common/darwin/Classes/FlutterWebRTCPlugin.m index f3c433e988..f2cbfbbd80 100644 --- a/common/darwin/Classes/FlutterWebRTCPlugin.m +++ b/common/darwin/Classes/FlutterWebRTCPlugin.m @@ -275,6 +275,18 @@ - (void)didSessionRouteChange:(NSNotification*)notification { routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange || routeChangeReason == AVAudioSessionRouteChangeReasonOverride)) { postEvent(self.eventSink, @{@"event" : @"onDeviceChange"}); + + // Report the newly-active audio output + AVAudioSessionPortDescription* output = + [RTCAudioSession sharedInstance].currentRoute.outputs.firstObject; + if (output != nil) { + postEvent(self.eventSink, @{ + @"event" : @"onAudioRouteChange", + @"deviceId" : output.UID ?: @"", + @"label" : output.portName ?: @"", + @"groupId" : output.portType ?: @"", + }); + } } #endif } diff --git a/ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterWebRTCPlugin.m b/ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterWebRTCPlugin.m index 90057df8c3..e6923a6b92 100644 --- a/ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterWebRTCPlugin.m +++ b/ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterWebRTCPlugin.m @@ -267,6 +267,18 @@ - (void)didSessionRouteChange:(NSNotification*)notification { routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange || routeChangeReason == AVAudioSessionRouteChangeReasonOverride)) { postEvent(self.eventSink, @{@"event" : @"onDeviceChange"}); + + // Report the newly-active audio output + AVAudioSessionPortDescription* output = + [RTCAudioSession sharedInstance].currentRoute.outputs.firstObject; + if (output != nil) { + postEvent(self.eventSink, @{ + @"event" : @"onAudioRouteChange", + @"deviceId" : output.UID ?: @"", + @"label" : output.portName ?: @"", + @"groupId" : output.portType ?: @"", + }); + } } // When stereo playout is preferred, debounce-refresh stereo playout state