• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SCREEN_CAPTURE_MONITOR_NAPI_H
17 #define SCREEN_CAPTURE_MONITOR_NAPI_H
18 
19 #include "screen_capture_monitor.h"
20 #include "screen_capture_monitor_callback.h"
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "common_napi.h"
24 
25 namespace OHOS {
26 namespace Media {
27 
28 const std::string EVENT_SYSTEM_SCREEN_RECORD = "systemScreenRecorder";
29 
30 class ScreenCaptureMonitorNapi {
31 public:
32     __attribute__((visibility("default"))) static napi_value Init(napi_env env, napi_value exports);
33 
34 private:
35     static napi_value Constructor(napi_env env, napi_callback_info info);
36     static void Destructor(napi_env env, void *nativeObject, void *finalize);
37 
38     /**
39      * getScreenCaptureMonitor(): Promise<ScreenCaptureMonitor>
40      */
41     static napi_value JsGetScreenCaptureMonitor(napi_env env, napi_callback_info info);
42     /**
43      * on(type: 'systemScreenRecorder', callback: (event: ScreenCaptureEvent) => void): void
44      */
45     static napi_value JsSetEventCallback(napi_env env, napi_callback_info info);
46     /**
47      * off(type: 'systemScreenRecorder'): void;
48      */
49     static napi_value JsCancelEventCallback(napi_env env, napi_callback_info info);
50     /**
51      * readonly isSystemScreenRecorderWorking: boolean;
52     */
53     static napi_value JsIsSystemScreenRecorderWorking(napi_env env, napi_callback_info info);
54     static ScreenCaptureMonitorNapi* GetJsInstanceAndArgs(napi_env env, napi_callback_info info,
55         size_t &argCount, napi_value *args);
56 
57     ScreenCaptureMonitorNapi();
58     ~ScreenCaptureMonitorNapi();
59 
60     void SetCallbackReference(const std::string &callbackName, std::shared_ptr<AutoRef> ref);
61     void CancelCallbackReference(const std::string &callbackName);
62 
63     static thread_local napi_ref constructor_;
64     napi_env env_ = nullptr;
65 
66     sptr<ScreenCaptureMonitor::ScreenCaptureMonitorListener> monitorCb_ = nullptr;
67     std::map<std::string, std::shared_ptr<AutoRef>> eventCbMap_;
68 };
69 
70 struct ScreenCaptureMonitorAsyncContext : public MediaAsyncContext {
ScreenCaptureMonitorAsyncContextScreenCaptureMonitorAsyncContext71     explicit ScreenCaptureMonitorAsyncContext(napi_env env) : MediaAsyncContext(env) {}
72     ~ScreenCaptureMonitorAsyncContext() = default;
73 };
74 
75 } // Media
76 } // OHOS
77 #endif