Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Stop receivers before closing Cast sessions

Neeraj Gupta627f74cb0b17
diff --git a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart
index b4482e59ec..02632a2df1 100644
--- a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart
+++ b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart
@@ -75,26 +75,14 @@ class CastService {
if (session == null) {
return;
}
-
- try {
- final receiverSessionID = session.receiverSessionID;
- if (receiverSessionID != null) {
- session.connection.sendToPlatformReceiver(
- ChromecastConnection.receiverNamespace,
- {"type": "STOP", "sessionId": receiverSessionID},
- );
- await session.connection.flush();
- }
- } finally {
- await _disconnectSession(session);
- }
+ await _stopSession(session);
}
Future<void> closeActiveCasts() async {
if (!isSupported) {
return;
}
- await Future.wait(_sessions.values.toList().map(_disconnectSession));
+ await Future.wait(_sessions.values.toList().map(_stopSession));
}
Map<String, String> getActiveSessions() {
@@ -184,6 +172,21 @@ class CastService {
return session.closeFuture ??= _closeSession(session);
}
+ Future<void> _stopSession(_CastSession session) async {
+ try {
+ final receiverSessionID = session.receiverSessionID;
+ if (receiverSessionID != null) {
+ session.connection.sendToPlatformReceiver(
+ ChromecastConnection.receiverNamespace,
+ {"type": "STOP", "sessionId": receiverSessionID},
+ );
+ await session.connection.flush();
+ }
+ } finally {
+ await _disconnectSession(session);
+ }
+ }
+
Future<void> _closeSession(_CastSession session) async {
if (identical(_sessions[session.device.serviceName], session)) {
_sessions.remove(session.device.serviceName);