stopRecording method
Implementation
Future<CockpitRecordingResult> stopRecording({
required CockpitRecordingSession session,
}) async {
final payload = await _channel
.invokeMethod<Object?>('stopRecording', <String, Object?>{
'purpose': session.request.purpose.name,
'name': session.request.name,
'relativePath': cockpitRecordingRelativePathFor(session.request),
});
if (payload is! Map<Object?, Object?>) {
throw StateError('Stop recording returned an invalid payload.');
}
final state = CockpitRecordingState.fromJson(
_requiredField<String>(payload, 'state'),
);
final rawBytes = _optionalField<Uint8List>(payload, 'bytes');
final rawSourceFilePath = _optionalField<String>(payload, 'sourceFilePath');
final completed = state == CockpitRecordingState.completed;
final bytes = completed && rawBytes != null && rawBytes.isNotEmpty
? rawBytes
: null;
final sourceFilePath =
completed &&
rawSourceFilePath != null &&
rawSourceFilePath.trim().isNotEmpty
? rawSourceFilePath
: null;
final hasUsableSource = bytes != null || sourceFilePath != null;
final relativePath = cockpitRecordingRelativePathFor(session.request);
return CockpitRecordingResult(
state: state,
purpose: session.request.purpose,
recordingKind: _optionalField<String>(payload, 'recordingKind') == null
? CockpitRecordingKind.nativeScreen
: CockpitRecordingKind.fromJson(payload['recordingKind']),
requestedMode: session.request.mode,
requestedLayer: session.request.layer,
effectiveLayer: _optionalField<String>(payload, 'effectiveLayer') == null
? session.request.layer
: CockpitRecordingLayer.fromJson(payload['effectiveLayer']),
fallbackUsed: _optionalField<bool>(payload, 'fallbackUsed') ?? false,
fallbackReason: _optionalField<String>(payload, 'fallbackReason'),
artifact: completed && hasUsableSource
? CockpitArtifactRef(role: 'recording', relativePath: relativePath)
: null,
durationMs: _optionalField<int>(payload, 'durationMs'),
bytes: bytes,
sourceFilePath: sourceFilePath,
failureReason: _optionalField<String>(payload, 'failureReason'),
);
}