toggleCamera method
- CameraName name, {
- required bool enable,
Enables or disables the given camera.
This function is called automatically, so if the camera is not connected or otherwise available, it'll fail silently. However, if the server simply doesn't respond, it'll show a warning.
Implementation
Future<void> toggleCamera(CameraName name, {required bool enable}) async {
final details = feeds[name]!.details;
if (enable && details.status != CameraStatus.CAMERA_DISABLED) return;
if (!enable && details.status == CameraStatus.CAMERA_DISCONNECTED) return;
_handshake = null;
details.status = enable ? CameraStatus.CAMERA_ENABLED : CameraStatus.CAMERA_DISABLED;
final command = VideoCommand(id: feeds[name]!.id, details: details);
models.sockets.video.sendMessage(command);
await Future<void>.delayed(const Duration(seconds: 2));
if (_handshake == null) {
models.home.setMessage(
severity: Severity.warning,
text: "Could not ${enable ? 'enable' : 'disable'} the ${name.humanName} camera",
);
}
}