mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
fix some disconnect command ordering issues and unawaited futures
This commit is contained in:
parent
c52e03abfc
commit
4cc5ae472a
@ -83,7 +83,7 @@ class CastNotifier extends StateNotifier<CastManagerState> {
|
||||
_gCastService.seekTo(position);
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
_gCastService.disconnect();
|
||||
Future<void> disconnect() async {
|
||||
await _gCastService.disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ class GCastRepository {
|
||||
"sessionId": sessionID,
|
||||
});
|
||||
|
||||
// wait 500ms to ensure the stop command is processed
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
await _castSession?.close();
|
||||
}
|
||||
|
||||
|
@ -56,16 +56,19 @@ class GCastService implements ICastDestinationService {
|
||||
}
|
||||
|
||||
void _onCastStatusCallback(CastSessionState state) {
|
||||
print("Cast session state changed: $state");
|
||||
if (state == CastSessionState.connected) {
|
||||
onConnectionState?.call(true);
|
||||
isConnected = true;
|
||||
} else if (state == CastSessionState.closed) {
|
||||
onConnectionState?.call(false);
|
||||
isConnected = false;
|
||||
onReceiverName?.call("");
|
||||
}
|
||||
}
|
||||
|
||||
void _onCastMessageCallback(Map<String, dynamic> message) {
|
||||
print("Received cast message: $message");
|
||||
switch (message['type']) {
|
||||
case "MEDIA_STATUS":
|
||||
_handleMediaStatus(message);
|
||||
@ -143,8 +146,9 @@ class GCastService implements ICastDestinationService {
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
await _gCastRepository.disconnect();
|
||||
onReceiverName?.call("");
|
||||
currentAssetId = null;
|
||||
await _gCastRepository.disconnect();
|
||||
}
|
||||
|
||||
bool isSessionValid() {
|
||||
@ -166,6 +170,7 @@ class GCastService implements ICastDestinationService {
|
||||
|
||||
@override
|
||||
void loadMedia(Asset asset, bool reload) async {
|
||||
print("Loading media for asset: ${asset.remoteId}");
|
||||
if (!isConnected) {
|
||||
return;
|
||||
} else if (asset.remoteId == null) {
|
||||
@ -174,6 +179,8 @@ class GCastService implements ICastDestinationService {
|
||||
return;
|
||||
}
|
||||
|
||||
print("tried to send it!");
|
||||
|
||||
// create a session key
|
||||
if (!isSessionValid()) {
|
||||
sessionKey = await _sessionsApiService.createSession(
|
||||
|
@ -110,11 +110,13 @@ class CastDialog extends ConsumerWidget {
|
||||
: isDeviceConnecting(deviceName)
|
||||
? const CircularProgressIndicator()
|
||||
: null,
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
if (isDeviceConnecting(deviceName)) {
|
||||
return;
|
||||
}
|
||||
ref.read(castProvider.notifier).disconnect();
|
||||
|
||||
await ref.read(castProvider.notifier).disconnect();
|
||||
|
||||
ref.read(castProvider.notifier).connect(type, deviceObj);
|
||||
},
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user