目录
1.背景
2.解决方案
1.背景
在OpenHarmony中调用以太网热插拔时间,发现热插拔没有任何回调,如下接口
import { ethernet } from '@kit.NetworkKit';ethernet.on('interfaceStateChange', (data: object) => {console.log('on interfaceSharingStateChange:' + JSON.stringify(data));
});
2.解决方案
原因是注册以太网napi接口时未设置env参数,解决方案如下:
--- a/sig/foundation/communication/netmanager_ext/frameworks/js/napi/ethernet/ethernet_module.cpp
+++ b/sig/foundation/communication/netmanager_ext/frameworks/js/napi/ethernet/ethernet_module.cpp
@@ -111,6 +111,7 @@ napi_value RegisterEthernetInterface(napi_env env, napi_value exports)napi_value ipSetMOdes = NapiUtils::CreateObject(env);NapiUtils::DefineProperties(env, ipSetMOdes, ipSetMode);NapiUtils::SetNamedProperty(env, exports, IP_SET_MODE, ipSetMOdes);
+ NapiUtils::SetEnvValid(env);return exports;}