mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-27 17:22:02 +00:00
!158 fix(js): modify js module name
Merge pull request !158 from Zhangfeng/master
This commit is contained in:
commit
51b37538c0
25
README.md
25
README.md
@ -40,11 +40,12 @@ The WLAN module provides basic WLAN functions, peer-to-peer \(P2P\) connection,
|
||||
|
||||
### Available APIs<a name="section1551164914237"></a>
|
||||
|
||||
The following table describes JavaScript APIs in **@ohos.wifi\_native\_js** available for basic WLAN functions.
|
||||
The following table describes JavaScript APIs in **@ohos.wifi** available for basic WLAN functions.
|
||||
|
||||
**Table 1** Major JavaScript APIs available for basic WLAN functions
|
||||
|
||||
<a name="t96d5b1a809be46328adc684bff001cf7"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r5b6b790b6fe144e79e849b7987637f32"><th class="cellrowborder" valign="top" width="27.642764276427638%" id="mcps1.2.4.1.1"><p id="a4bf77d9c2b5c4b8d950a720edaf949c7"><a name="a4bf77d9c2b5c4b8d950a720edaf949c7"></a><a name="a4bf77d9c2b5c4b8d950a720edaf949c7"></a>API</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="41.094109410941094%" id="mcps1.2.4.1.2"><p id="a11b93aaf8bfd4305acc4b4549f28d524"><a name="a11b93aaf8bfd4305acc4b4549f28d524"></a><a name="a11b93aaf8bfd4305acc4b4549f28d524"></a>Description</p>
|
||||
@ -132,16 +133,16 @@ The following table describes JavaScript APIs in **@ohos.wifi\_native\_js** av
|
||||
|
||||
Before invoking WLAN JavaScript APIs, you need to import the **@ohos.wifi\_native\_js** class.
|
||||
|
||||
```
|
||||
import wifi_native_js from '@ohos.wifi_native_js'; // Import the @ohos.wifi_native_js class.
|
||||
```js
|
||||
import wf from '@ohos.wifi'; // Import the @ohos.wifi class.
|
||||
```
|
||||
|
||||
- Obtaining the WLAN state
|
||||
|
||||
1. Call the **isWifiActive\(\)** method to check whether WLAN is enabled.
|
||||
|
||||
```
|
||||
var isWifiActive = wifi_native_js.isWifiActive(); // Value true indicates that WLAN is enabled, and false indicates the opposite.
|
||||
```js
|
||||
var isWifiActive = wf.isWifiActive(); // Value true indicates that WLAN is enabled, and false indicates the opposite.
|
||||
```
|
||||
|
||||
|
||||
@ -150,14 +151,14 @@ import wifi_native_js from '@ohos.wifi_native_js'; // Import the @ohos.wifi_nati
|
||||
1. Call the **scan\(\)** method to start a scan.
|
||||
2. Call the **getScanInfoList\(\)** method to obtain the scan result.
|
||||
|
||||
```
|
||||
```js
|
||||
// Start a scan.
|
||||
var isScanSuccess = wifi_native_js.scan(); // true
|
||||
var isScanSuccess = wf.scan(); // true
|
||||
|
||||
// Wait for some time.
|
||||
|
||||
// Obtain the scan result.
|
||||
wifi_native_js.getScanInfos(result => {
|
||||
wf.getScanInfos(result => {
|
||||
var num = Object.keys(result).length;
|
||||
console.info("wifi scan result mum: " + num);
|
||||
for (var i = 0; i < num; ++i) {
|
||||
@ -177,7 +178,7 @@ Set up a WLAN connection.
|
||||
|
||||
1. Call **addDeviceConfig** to add a hotspot configuration, and set up a WLAN based on the hotspot configuration ID or by calling **connectToDevice** with the hotspot configuration passed.
|
||||
|
||||
```
|
||||
```js
|
||||
// Configure WLAN information.
|
||||
var config = {
|
||||
"ssid":"test_wifi",
|
||||
@ -188,14 +189,14 @@ Set up a WLAN connection.
|
||||
}
|
||||
Method 1:
|
||||
// Add a hotspot configuration.
|
||||
wifi_native_js.addDeviceConfig(config, (result) => {
|
||||
wf.addDeviceConfig(config, (result) => {
|
||||
console.info("config id: " + result);
|
||||
// Set up a WLAN based on the hotspot configuration ID.
|
||||
wifi_native_js.connectToNetwork(result);
|
||||
wf.connectToNetwork(result);
|
||||
});
|
||||
Method 2:
|
||||
// Set up a WLAN by calling connectToDevice with the hotspot configuration passed.
|
||||
wifi_native_js.connectToDevice(config);
|
||||
wf.connectToDevice(config);
|
||||
```
|
||||
|
||||
|
||||
|
25
README_zh.md
25
README_zh.md
@ -40,11 +40,12 @@ WLAN组件子系统为用户提供WLAN基础功能、P2P(peer-to-peer)功能
|
||||
|
||||
### 接口说明<a name="section1551164914237"></a>
|
||||
|
||||
WLAN基础功能由@ohos.wifi\_native\_js类提供,其接口\(JS接口\)说明如下。
|
||||
WLAN基础功能由@ohos.wifi类提供,其接口\(JS接口\)说明如下。
|
||||
|
||||
**表 1** WLAN基础功能的主要接口\(JS接口\)
|
||||
|
||||
<a name="t96d5b1a809be46328adc684bff001cf7"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r5b6b790b6fe144e79e849b7987637f32"><th class="cellrowborder" valign="top" width="40.864086408640865%" id="mcps1.2.4.1.1"><p id="a4bf77d9c2b5c4b8d950a720edaf949c7"><a name="a4bf77d9c2b5c4b8d950a720edaf949c7"></a><a name="a4bf77d9c2b5c4b8d950a720edaf949c7"></a>接口名</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.704470447044706%" id="mcps1.2.4.1.2"><p id="a11b93aaf8bfd4305acc4b4549f28d524"><a name="a11b93aaf8bfd4305acc4b4549f28d524"></a><a name="a11b93aaf8bfd4305acc4b4549f28d524"></a>描述</p>
|
||||
@ -132,16 +133,16 @@ WLAN基础功能由@ohos.wifi\_native\_js类提供,其接口\(JS接口\)说明
|
||||
|
||||
在调用WLAN JS接口前需要导入接口类。
|
||||
|
||||
```
|
||||
import wifi_native_js from '@ohos.wifi_native_js'; // 导入js接口类
|
||||
```js
|
||||
import wf from '@ohos.wifi'; // 导入js接口类
|
||||
```
|
||||
|
||||
(一)获取WLAN状态
|
||||
|
||||
1. 调用isWifiActive\(\)接口查询WLAN是否打开。
|
||||
|
||||
```
|
||||
var isWifiActive = wifi_native_js.isWifiActive(); // 若WLAN打开,则返回true,否则返回false
|
||||
```js
|
||||
var isWifiActive = wf.isWifiActive(); // 若WLAN打开,则返回true,否则返回false
|
||||
```
|
||||
|
||||
|
||||
@ -150,14 +151,14 @@ import wifi_native_js from '@ohos.wifi_native_js'; // 导入js接口类
|
||||
1. 调用scan\(\)接口发起扫描。
|
||||
2. 调用getScanInfoList\(\)接口获取扫描结果。
|
||||
|
||||
```
|
||||
```js
|
||||
// 调用WLAN扫描接口
|
||||
var isScanSuccess = wifi_native_js.scan(); // true
|
||||
var isScanSuccess = wf.scan(); // true
|
||||
|
||||
// 延迟一定时间
|
||||
|
||||
// 获取扫描结果
|
||||
wifi_native_js.getScanInfos(result => {
|
||||
wf.getScanInfos(result => {
|
||||
var num = Object.keys(result).length;
|
||||
console.info("wifi scan result mum: " + num);
|
||||
for (var i = 0; i < num; ++i) {
|
||||
@ -177,7 +178,7 @@ import wifi_native_js from '@ohos.wifi_native_js'; // 导入js接口类
|
||||
|
||||
1. 调用addDeviceConfig添加配置,然后通过返回的配置id连接WLAN或调用connectToDevice通过配置直接连接WLAN。
|
||||
|
||||
```
|
||||
```js
|
||||
// WLAN配置信息
|
||||
var config = {
|
||||
"ssid":"test_wifi",
|
||||
@ -188,14 +189,14 @@ import wifi_native_js from '@ohos.wifi_native_js'; // 导入js接口类
|
||||
}
|
||||
方式一:
|
||||
// 添加配置
|
||||
wifi_native_js.addDeviceConfig(config, (result) => {
|
||||
wf.addDeviceConfig(config, (result) => {
|
||||
console.info("config id: " + result);
|
||||
// 通过配置id连接WLAN
|
||||
wifi_native_js.connectToNetwork(result);
|
||||
wf.connectToNetwork(result);
|
||||
});
|
||||
方式二:
|
||||
// 通过配置信息直接连接WLAN
|
||||
wifi_native_js.connectToDevice(config);
|
||||
wf.connectToDevice(config);
|
||||
```
|
||||
|
||||
|
||||
|
@ -13,6 +13,46 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("wifi") {
|
||||
install_enable = true
|
||||
include_dirs = [
|
||||
"//third_party/node/src",
|
||||
"//native_engine",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
|
||||
"//base/notification/ces_standard/frameworks/core/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"wifi_napi_device.cpp",
|
||||
"wifi_napi_entry.cpp",
|
||||
"wifi_napi_event.cpp",
|
||||
"wifi_napi_hotspot.cpp",
|
||||
"wifi_napi_p2p.cpp",
|
||||
"wifi_napi_utils.cpp",
|
||||
]
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//base/notification/ces_standard/frameworks/core:cesfwk_core",
|
||||
"//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [ "ipc:ipc_core" ]
|
||||
|
||||
relative_install_dir = "module"
|
||||
part_name = "wifi_native_js"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
||||
ohos_shared_library("wifi_native_js") {
|
||||
install_enable = true
|
||||
include_dirs = [
|
||||
@ -52,7 +92,3 @@ ohos_shared_library("wifi_native_js") {
|
||||
part_name = "wifi_native_js"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
||||
group("wifi_js") {
|
||||
deps = [ ":wifi_native_js" ]
|
||||
}
|
||||
|
@ -87,6 +87,40 @@ static napi_module wifiJsModule = {
|
||||
.nm_flags = 0,
|
||||
.nm_filename = NULL,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "wifi",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = { 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Module initialization function
|
||||
*/
|
||||
static napi_value InitForCompatible(napi_env env, napi_value exports) {
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("enableWifi", EnableWifi),
|
||||
DECLARE_NAPI_FUNCTION("disableWifi", DisableWifi),
|
||||
DECLARE_NAPI_FUNCTION("isWifiActive", IsWifiActive),
|
||||
DECLARE_NAPI_FUNCTION("scan", Scan),
|
||||
DECLARE_NAPI_FUNCTION("getScanInfos", GetScanInfos),
|
||||
DECLARE_NAPI_FUNCTION("addDeviceConfig", AddDeviceConfig),
|
||||
DECLARE_NAPI_FUNCTION("connectToNetwork", ConnectToNetwork),
|
||||
DECLARE_NAPI_FUNCTION("connectToDevice", ConnectToDevice),
|
||||
DECLARE_NAPI_FUNCTION("disconnect", Disconnect),
|
||||
DECLARE_NAPI_FUNCTION("getSignalLevel", GetSignalLevel),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
|
||||
return exports;
|
||||
}
|
||||
|
||||
/* @Deprecated - Changeme module name from "wifi_native_js" to "wifi",
|
||||
* "wifi_native_js" will be discarded. Modify @11/2021
|
||||
*/
|
||||
static napi_module wifiJsModuleForCompatible = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = NULL,
|
||||
.nm_register_func = InitForCompatible,
|
||||
.nm_modname = "wifi_native_js",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = { 0 }
|
||||
@ -94,6 +128,7 @@ static napi_module wifiJsModule = {
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void) {
|
||||
napi_module_register(&wifiJsModule);
|
||||
napi_module_register(&wifiJsModuleForCompatible);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -81,7 +81,8 @@
|
||||
|
||||
"wifi_native_js": {
|
||||
"module_list": [
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/napi:wifi_native_js"
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/napi:wifi_native_js",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/napi:wifi"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user