From 829208835a143c5bed525bce1ee7d21b6a8c5726 Mon Sep 17 00:00:00 2001 From: dujingcheng Date: Thu, 16 Sep 2021 12:34:40 +0000 Subject: [PATCH] dujingcheng@huawei.com Signed-off-by: dujingcheng --- frameworks/bridge/common/dom/dom_camera.cpp | 33 +++++++++++++++++++ frameworks/bridge/common/dom/dom_camera.h | 1 + frameworks/bridge/common/dom/dom_type.cpp | 2 ++ frameworks/bridge/common/dom/dom_type.h | 2 ++ .../core/components/camera/camera_element.cpp | 2 ++ 5 files changed, 40 insertions(+) diff --git a/frameworks/bridge/common/dom/dom_camera.cpp b/frameworks/bridge/common/dom/dom_camera.cpp index 5441e9a8a9e..d8d2e0b881f 100644 --- a/frameworks/bridge/common/dom/dom_camera.cpp +++ b/frameworks/bridge/common/dom/dom_camera.cpp @@ -30,6 +30,7 @@ const char FLUSH_ON[] = "on"; const char FLUSH_OFF[] = "off"; const char FLUSH_TORCH[] = "torch"; const char FLUSH_AUTO[] = "auto"; +const char START_STR[] = "[\""; } // namespace @@ -85,12 +86,27 @@ bool DOMCamera::AddSpecializedEvent(int32_t pageId, const std::string& event) void DOMCamera::CallSpecializedMethod(const std::string& method, const std::string& args) { + LOGI("DOMCamera: method: %{public}s args: %{public}s", method.c_str(), args.c_str()); if (method == DOM_TAKE_PHOTO) { auto controller = cameraComponent_->GetCameraController(); if (controller) { controller->TakePhoto(GetParamFromJson(args)); } } + + if (method == DOM_CAMERA_START_RECORD) { + auto controller = cameraComponent_->GetCameraController(); + if (controller) { + controller->StartRecord(); + } + } + + if (method == DOM_CAMERA_CLOSE_RECORDER) { + auto controller = cameraComponent_->GetCameraController(); + if (controller) { + controller->CloseRecorder(GetRecorderParam(args)); + } + } } TakePhotoParams DOMCamera::GetParamFromJson(const std::string& args) const @@ -126,6 +142,23 @@ TakePhotoParams DOMCamera::GetParamFromJson(const std::string& args) const return takePhotoParams; } +std::string DOMCamera::GetRecorderParam(const std::string& args) const +{ + size_t len = args.length(); + size_t pos = args.find(START_STR); + size_t strLen = sizeof(START_STR) - 1; + int32_t result = 0; + + if (pos == std::string::npos || (pos + strLen) >= len) { + return std::string(); + } + std::stringstream ss; + ss << args.substr(pos + strLen); + ss >> result; + + return std::to_string(result); +} + FlashType DOMCamera::GetFlashType(const std::string& val) { static const std::unordered_map flashTypes = { diff --git a/frameworks/bridge/common/dom/dom_camera.h b/frameworks/bridge/common/dom/dom_camera.h index 0852c42ae8b..b3bbbf2bce3 100644 --- a/frameworks/bridge/common/dom/dom_camera.h +++ b/frameworks/bridge/common/dom/dom_camera.h @@ -39,6 +39,7 @@ protected: void CallSpecializedMethod(const std::string& method, const std::string& args) override; TakePhotoParams GetParamFromJson(const std::string& args) const; + std::string GetRecorderParam(const std::string& args) const; static FlashType GetFlashType(const std::string& val); static DevicePosition GetDevicePosition(const std::string& val); diff --git a/frameworks/bridge/common/dom/dom_type.cpp b/frameworks/bridge/common/dom/dom_type.cpp index 72be3150ed2..3b18a7fc4cc 100644 --- a/frameworks/bridge/common/dom/dom_type.cpp +++ b/frameworks/bridge/common/dom/dom_type.cpp @@ -1240,6 +1240,8 @@ const char DOM_ZINDEX[] = "zIndex"; const char DOM_TAKE_PHOTO[] = "takePhoto"; const char DOM_CAMERA_FLASH[] = "flash"; const char DOM_CAMERA_DEVICE_POSITION[] = "deviceposition"; +const char DOM_CAMERA_START_RECORD[] = "startRecorder"; +const char DOM_CAMERA_CLOSE_RECORDER[] = "closeRecorder"; // form const char DOM_FORM_EVENT_SUBMIT[] = "submit"; diff --git a/frameworks/bridge/common/dom/dom_type.h b/frameworks/bridge/common/dom/dom_type.h index 01af4656faa..530d4df0284 100644 --- a/frameworks/bridge/common/dom/dom_type.h +++ b/frameworks/bridge/common/dom/dom_type.h @@ -1244,6 +1244,8 @@ ACE_EXPORT extern const char DOM_ZINDEX[]; ACE_EXPORT extern const char DOM_TAKE_PHOTO[]; ACE_EXPORT extern const char DOM_CAMERA_FLASH[]; ACE_EXPORT extern const char DOM_CAMERA_DEVICE_POSITION[]; +ACE_EXPORT extern const char DOM_CAMERA_START_RECORD[]; +ACE_EXPORT extern const char DOM_CAMERA_CLOSE_RECORDER[]; // form ACE_EXPORT extern const char DOM_FORM_EVENT_SUBMIT[]; diff --git a/frameworks/core/components/camera/camera_element.cpp b/frameworks/core/components/camera/camera_element.cpp index 98d0d90dafc..e79069321db 100644 --- a/frameworks/core/components/camera/camera_element.cpp +++ b/frameworks/core/components/camera/camera_element.cpp @@ -420,6 +420,7 @@ void CameraElement::TakePhoto(const Size& size) void CameraElement::StartRecord() { + LOGI("CameraElement::StartRecord."); if (camera_ && !isRecording_) { camera_->StartRecord(); isRecording_ = true; @@ -428,6 +429,7 @@ void CameraElement::StartRecord() void CameraElement::CloseRecorder(const std::string& params) { + LOGI("CameraElement::CloseRecorder."); auto context = context_.Upgrade(); if (!context) { LOGE("fail to get context");