• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_DISTRIBUTED_ABILITY_CONNECTION_MANAGER_JS_ABILITY_CONNECTION_SESSION_LISTENER_H
17 #define OHOS_DISTRIBUTED_ABILITY_CONNECTION_MANAGER_JS_ABILITY_CONNECTION_SESSION_LISTENER_H
18 
19 #include <map>
20 
21 #include "ability_connection_info.h"
22 #include "native_engine/native_engine.h"
23 
24 namespace OHOS {
25 namespace DistributedCollab {
26 class JsAbilityConnectionSessionListener {
27 public:
JsAbilityConnectionSessionListener(napi_env env)28     explicit JsAbilityConnectionSessionListener(napi_env env) : env_(env) {}
29     virtual ~JsAbilityConnectionSessionListener() = default;
30     void CallJsMethod(const EventCallbackInfo& eventCallbackInfo);
31     void CallJsMethod(const CollaborateEventInfo& collaborateEventInfo);
32     void SetCallback(const napi_value& jsListenerObj);
33 
34 private:
35     // EventCallbackInfo
36     void CallJsMethodInner(const EventCallbackInfo& eventCallbackInfo);
37     napi_value WrapEventCallbackInfo(napi_env& env, const EventCallbackInfo& eventCallbackInfo);
38     // CollaborateEventInfo
39     void CallJsMethodInner(const CollaborateEventInfo& collaborateEventInfo);
40     napi_value WrapEventCallbackInfo(napi_env& env, const CollaborateEventInfo& collaborateEventInfo);
41 
42     template <typename T>
43     void CallJsMethodTemplate(const T& callbackInfo);
44     template <typename T>
45     void CallJsMethodInnerTemplate(const T& callbackInfo);
46     napi_value WrapAVTransDataBuffer(napi_env& env, const std::shared_ptr<AVTransDataBuffer>& dataBuffer);
47 
48 private:
49     napi_env env_ = nullptr;
50     std::unique_ptr<NativeReference> callbackRef_ = nullptr;
51 };
52 } // namespace DistributedCollab
53 } // namespace OHOS
54 #endif // OHOS_DISTRIBUTED_ABILITY_CONNECTION_MANAGER_JS_ABILITY_CONNECTION_SESSION_LISTENER_H