Skip to content

Commit 1554daa

Browse files
Address code review: log errors in StopAsync, remove redundant catch, document SessionManager
Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
1 parent a6f5499 commit 1554daa

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

AirPlay/Listeners/AirTunesListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ public override async Task OnDataReceivedAsync(Request request, Response respons
446446
// (ports 7002/7003 must be released first)
447447
if (session.AudioControlListener != null)
448448
{
449-
try { await session.AudioControlListener.StopAsync(); } catch { }
449+
try { await session.AudioControlListener.StopAsync(); }
450+
catch (Exception ex) { Console.WriteLine($"Error stopping old audio listener: {ex.Message}"); }
450451
session.AudioControlListener = null;
451452
}
452453

AirPlay/Listeners/MirroringListener.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ public override async Task OnRawReceivedAsync(TcpClient client, NetworkStream st
134134
session.SpsPps = spsPps;
135135
}
136136
}
137-
catch (OperationCanceledException)
138-
{
139-
break;
140-
}
141137
catch (Exception e)
142138
{
143139
Console.WriteLine($"Mirroring error: {e}");

AirPlay/Services/SessionManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public Task<Session> GetSessionAsync(string key)
2424
return Task.FromResult(_session ?? new Session(key));
2525
}
2626

27+
/// <summary>
28+
/// Store session state. Callers must always retrieve the session via GetSessionAsync first,
29+
/// modify it, then save it back. The incoming session replaces the old one entirely,
30+
/// allowing fields to be intentionally set to null (e.g., during TEARDOWN cleanup).
31+
/// </summary>
2732
public Task CreateOrUpdateSessionAsync(string key, Session session)
2833
{
2934
_sessions.AddOrUpdate(key, session, (k, old) => session);

0 commit comments

Comments
 (0)