[mob][photos] Add support for closing session
This commit is contained in:
parent
4b97f832b2
commit
7411125194
5 changed files with 36 additions and 13 deletions
|
@ -100,7 +100,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
|
|||
if (message.containsKey(CastMessageType.pairCode)) {
|
||||
final code = message[CastMessageType.pairCode]!['code'];
|
||||
widget.onConnect(code);
|
||||
// Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -583,9 +583,14 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
Tooltip(
|
||||
message: "Cast album",
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.cast_outlined),
|
||||
icon: castService.getActiveSessions().isNotEmpty
|
||||
? const Icon(Icons.cast_connected_rounded)
|
||||
: const Icon(Icons.cast_outlined),
|
||||
onPressed: () async {
|
||||
await _castChoiceDialog();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -855,6 +860,21 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
|
||||
Future<void> _castChoiceDialog() async {
|
||||
final gw = CastGateway(NetworkClient.instance.enteDio);
|
||||
if (castService.getActiveSessions().isNotEmpty) {
|
||||
await showChoiceDialog(
|
||||
context,
|
||||
title: "Stop casting",
|
||||
firstButtonLabel: "Yes",
|
||||
secondButtonLabel: "No",
|
||||
body: "Do you want to stop casting?",
|
||||
firstButtonOnTap: () async {
|
||||
gw.revokeAllTokens().ignore();
|
||||
await castService.closeActiveCasts();
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// stop any existing cast session
|
||||
gw.revokeAllTokens().ignore();
|
||||
final result = await showDialog<ButtonAction?>(
|
||||
|
|
|
@ -12,7 +12,7 @@ abstract class CastService {
|
|||
void Function(Map<CastMessageType, Map<String, dynamic>>)? onMessage,
|
||||
});
|
||||
// returns a map of sessionID to deviceNames
|
||||
Future<Map<String, String>> getActiveSessions();
|
||||
Map<String, String> getActiveSessions();
|
||||
|
||||
Future<void> closeActiveCasts();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CastServiceImpl extends CastService {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, String>> getActiveSessions() {
|
||||
Map<String, String> getActiveSessions() {
|
||||
// TODO: implement getActiveSessions
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
|
|
@ -70,24 +70,27 @@ class CastServiceImpl extends CastService {
|
|||
Future<void> closeActiveCasts() {
|
||||
final sessions = CastSessionManager().sessions;
|
||||
for (final session in sessions) {
|
||||
session.sendMessage(
|
||||
_pairRequestNamespace,
|
||||
{
|
||||
"type": "CLOSE",
|
||||
},
|
||||
);
|
||||
debugPrint("send close message for ${session.sessionId}");
|
||||
session.sendMessage(CastSession.kNamespaceConnection, {
|
||||
'type': 'CLOSE',
|
||||
});
|
||||
debugPrint("close session ${session.sessionId}");
|
||||
session.close();
|
||||
}
|
||||
CastSessionManager().sessions.clear();
|
||||
debugPrint("send close message");
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, String>> getActiveSessions() {
|
||||
Map<String, String> getActiveSessions() {
|
||||
final sessions = CastSessionManager().sessions;
|
||||
final Map<String, String> result = {};
|
||||
for (final session in sessions) {
|
||||
result[session.sessionId] = session.state.toString();
|
||||
if (session.state == CastSessionState.connected) {
|
||||
result[session.sessionId] = session.state.toString();
|
||||
}
|
||||
}
|
||||
return Future.value(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue