Skip to content

Commit e9e676d

Browse files
committed
fix clean up
1 parent 1a8edb7 commit e9e676d

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

lib/src/core/room.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
180180
onDispose(() async {
181181
// clean up routine
182182
await _cleanUp();
183+
// dispose preConnectAudioBuffer
184+
await preConnectAudioBuffer.dispose();
183185
// dispose events
184186
await events.dispose();
185187
// dispose local participant
@@ -452,7 +454,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
452454
publishOptions: roomOptions.defaultAudioPublishOptions.copyWith(preConnect: true),
453455
);
454456
}
455-
457+
456458
if (connectOptions.protocolVersion.index >= ProtocolVersion.v8.index &&
457459
engine.fastConnectOptions != null &&
458460
!engine.fullReconnectOnNext) {
@@ -977,7 +979,7 @@ extension RoomPrivateMethods on Room {
977979

978980
_activeSpeakers.clear();
979981

980-
await preConnectAudioBuffer.dispose();
982+
await preConnectAudioBuffer.reset();
981983

982984
// clean up engine
983985
await engine.cleanUp();

lib/src/events.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,13 @@ class PreConnectAudioBufferStartedEvent with RoomEvent {
609609
/// Emitted by [Room].
610610
class PreConnectAudioBufferStoppedEvent with RoomEvent {
611611
final int bufferedSize;
612-
final bool isDataSent;
612+
final bool isBufferSent;
613613
const PreConnectAudioBufferStoppedEvent({
614614
required this.bufferedSize,
615-
required this.isDataSent,
615+
required this.isBufferSent,
616616
});
617617

618618
@override
619619
String toString() => '${runtimeType}'
620-
'(bufferedSize: ${bufferedSize}, isDataSent: ${isDataSent})';
620+
'(bufferedSize: ${bufferedSize}, isDataSent: ${isBufferSent})';
621621
}

lib/src/preconnect/pre_connect_audio_buffer.dart

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PreConnectAudioBuffer {
3333

3434
// Internal states
3535
bool _isRecording = false;
36-
bool _isSent = false;
36+
bool _isBufferSent = false;
3737
String? _rendererId;
3838

3939
LocalAudioTrack? _localTrack;
@@ -167,7 +167,7 @@ class PreConnectAudioBuffer {
167167
// Emit the stopped event
168168
_room.events.emit(PreConnectAudioBufferStoppedEvent(
169169
bufferedSize: _buffer.length,
170-
isDataSent: _isSent,
170+
isBufferSent: _isBufferSent,
171171
));
172172

173173
logger.info('[Preconnect audio] stopped recording');
@@ -188,32 +188,22 @@ class PreConnectAudioBuffer {
188188
_localTrackPublishedEvent = null;
189189

190190
// Reset the _isSent flag to allow data sending on next use
191-
_isSent = false;
191+
_isBufferSent = false;
192192

193193
logger.info('[Preconnect audio] reset');
194194
}
195195

196196
// Dispose the audio buffer and clean up all resources.
197197
Future<void> dispose() async {
198-
// Ensure we stop recording first
199-
await stopRecording();
200-
201-
// Don't stop the local track - it will continue to be used by the Room
202-
_localTrack = null;
203-
204-
_agentReadyManager.dispose();
205-
_timeoutTimer?.cancel();
206-
_participantStateListener?.call();
207-
_participantStateListener = null;
208-
198+
await reset();
209199
logger.info('[Preconnect audio] disposed');
210200
}
211201

212202
Future<void> sendAudioData({
213203
required List<String> agents,
214204
String topic = dataTopic,
215205
}) async {
216-
if (_isSent) return;
206+
if (_isBufferSent) return;
217207
if (agents.isEmpty) return;
218208

219209
// Wait for local track published event
@@ -231,7 +221,7 @@ class PreConnectAudioBuffer {
231221
final data = _buffer.takeBytes();
232222
logger.info('[Preconnect audio] data.length: ${data.length}, bytes.length: ${_buffer.length}');
233223

234-
_isSent = true;
224+
_isBufferSent = true;
235225

236226
final streamOptions = StreamBytesOptions(
237227
topic: topic,

0 commit comments

Comments
 (0)