gpt4 book ai didi

javascript - cordova Zeroconf 如何支持?

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:04 25 4
gpt4 key购买 nike

我正在使用 bonjour 来提供我的服务在我的服务器上运行

var test= bonjour.publish({ name: "abcd", type: 'http', port: settings.server.port });
test.start();

在客户端运行:

function onDeviceReady() {

console.log('in deviceready')
var zeroconf = cordova.plugins.zeroconf;
console.log(zeroconf)

zeroconf.watch('abcd._http._tcp.local.', function (result) {
console.log('in zeroconf')
var action = result.action;
var service = result.service;
if (action == 'added') {
console.log('service added', service);
} else {
console.log('service removed', service);
}
});
console.log("test")
}

但是我的 zeroconf.watch 方法没有得到任何响应/成功。我添加了所需的插件,但没有任何效果...

最佳答案

我为我工作:

<script type="text/javascript">
function onDeviceReady() {
ZeroConf.watch('_http._tcp.local.', function(resp){
document.getElementById("zeroconf2").innerHTML = resp;
});
}
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
onLoad();
</script>

并将此行放入 config.xml

<gap:plugin name="cordova-zeroconf-plugin" source="npm" />

关于javascript - cordova Zeroconf 如何支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35157576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com