Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dispose LocalParticipant when room.disconnect. #609

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions example/lib/widgets/participant_stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class _ParticipantStatsWidgetState extends State<ParticipantStatsWidget> {
event.stats['f'] ?? event.stats['h'] ?? event.stats['q'];
if (firstStats != null) {
stats['encoder'] = firstStats.encoderImplementation ?? '';
stats['codec'] =
'${firstStats.mimeType!.split('/')[1]}/${firstStats.clockRate}';
if (firstStats.mimeType != null) {
stats['codec'] =
'${firstStats.mimeType!.split('/')[1]}/${firstStats.clockRate}';
}
stats['payload'] = '${firstStats.payloadType}';
stats['qualityLimitationReason'] =
firstStats.qualityLimitationReason ?? '';
Expand All @@ -54,8 +56,10 @@ class _ParticipantStatsWidgetState extends State<ParticipantStatsWidget> {
Map<String, String> stats = {};
setState(() {
stats['rx'] = '${event.currentBitrate.toInt()} kpbs';
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}';
if (event.stats.mimeType != null) {
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}';
}
stats['payload'] = '${event.stats.payloadType}';
stats['size/fps'] =
'${event.stats.frameWidth}x${event.stats.frameHeight} ${event.stats.framesPerSecond?.toDouble()}fps';
Expand All @@ -76,8 +80,10 @@ class _ParticipantStatsWidgetState extends State<ParticipantStatsWidget> {
Map<String, String> stats = {};
setState(() {
stats['tx'] = '${event.currentBitrate.toInt()} kpbs';
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}/${event.stats.channels}';
if (event.stats.mimeType != null) {
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}/${event.stats.channels}';
}
stats['payload'] = '${event.stats.payloadType}';
this.stats['audio']!.addEntries(stats.entries);
});
Expand All @@ -88,8 +94,10 @@ class _ParticipantStatsWidgetState extends State<ParticipantStatsWidget> {
Map<String, String> stats = {};
setState(() {
stats['rx'] = '${event.currentBitrate.toInt()} kpbs';
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}/${event.stats.channels}';
if (event.stats.mimeType != null) {
stats['codec'] =
'${event.stats.mimeType!.split('/')[1]}/${event.stats.clockRate}/${event.stats.channels}';
}
stats['payload'] = '${event.stats.payloadType}';
stats['jitter'] = '${event.stats.jitter} s';
//stats['concealed samples'] =
Expand Down
9 changes: 7 additions & 2 deletions lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
})
..on<EngineDisconnectedEvent>((event) async {
if (!engine.fullReconnectOnNext) {
await _cleanUp();
await _cleanUp(disposeLocalParticipant: false);
events.emit(RoomDisconnectedEvent(reason: event.reason));
notifyListeners();
}
Expand Down Expand Up @@ -887,7 +887,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {

extension RoomPrivateMethods on Room {
// resets internal state to a re-usable state
Future<void> _cleanUp() async {
Future<void> _cleanUp({bool disposeLocalParticipant = true}) async {
logger.fine('[${objectId}] cleanUp()');

// clean up RemoteParticipants
Expand All @@ -903,6 +903,11 @@ extension RoomPrivateMethods on Room {
// clean up LocalParticipant
await localParticipant?.unpublishAllTracks();

if (disposeLocalParticipant) {
await localParticipant?.dispose();
_localParticipant = null;
}

_activeSpeakers.clear();

// clean up engine
Expand Down
Loading