cameraState method
Implementation
@override
Future<Map<String, dynamic>> cameraState(String cameraId) async {
// if (isRequestPending) {
// return {
// "isError": true,
// "message": "PENDING_PREVIOUS_REQUEST",
// "details": "Called cameraState()"
// };
// }
// isRequestPending = true;
if (!isUserLogged || initializedCamera != cameraId) {
final apiResponse = await apiService.getDeviceMasterAccount(cameraId);
if (apiResponse['isError']) {
// isRequestPending = false;
return apiResponse;
}
final account = apiResponse["account"];
if (tempUsername != account["username"]) {
await methodChannel.invokeMethod('LOGIN', {
"userName": account["username"],
"password": account["password"],
});
}
isUserLogged = true;
tempUsername = account["username"];
tempPassword = account["password"];
tempCameraId = cameraId;
}
final state = await methodChannel
.invokeMethod('GET_CAMERA_STATE', {"cameraId": cameraId});
// isRequestPending = false;
if (state[0] == 0) return {"isError": false, "state": "OFF_LINE"};
if (state[0] == 1) return {"isError": false, "state": "ON_LINE"};
if (state[0] == 2) return {"isError": false, "state": "SLEEP"};
if (state[0] == 3) return {"isError": false, "state": "WAKE_UP"};
if (state[0] == 4) return {"isError": false, "state": "WAKE"};
if (state[0] == 5) return {"isError": false, "state": "SLEEP_UNWAKE"};
if (state[0] == 6) return {"isError": false, "state": "PREPARE_SLEEP"};
return {"isError": true, "message": "PREPARE_SLEEP"};
}