Skip to content

Commit f890929

Browse files
committed
Stop native audio on error
1 parent 4413fe5 commit f890929

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/src/core/room_preconnect.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extension RoomPreConnect on Room {
3232
await preConnectAudioBuffer.agentReadyFuture;
3333
return result;
3434
} catch (error) {
35+
await preConnectAudioBuffer.stopRecording(withError: error);
3536
logger.warning('[Preconnect] operation failed with error: $error');
3637
rethrow;
3738
} finally {

lib/src/preconnect/pre_connect_audio_buffer.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,8 @@ class PreConnectAudioBuffer {
154154
));
155155
}
156156

157-
Future<void> stopRecording() async {
158-
if (!_isRecording) {
159-
logger.warning('Not recording');
160-
return;
161-
}
157+
Future<void> stopRecording({Object? withError}) async {
158+
if (!_isRecording) return;
162159
_isRecording = false;
163160

164161
// Cancel the stream subscription.
@@ -177,6 +174,11 @@ class PreConnectAudioBuffer {
177174

178175
_rendererId = null;
179176

177+
// Stop native audio when errored
178+
if (withError != null) {
179+
await webrtc.NativeAudioManagement.stopLocalRecording();
180+
}
181+
180182
// Complete agent ready future if not already completed
181183
_agentReadyManager.complete();
182184

0 commit comments

Comments
 (0)