Javascript cordova zeroconf如何支持?
我用Javascript cordova zeroconf如何支持?,javascript,node.js,cordova,zeroconf,Javascript,Node.js,Cordova,Zeroconf,我用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.lo
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>
函数ondevicerady(){
ZeroConf.watch(“http.\tcp.local.”,函数(resp){
document.getElementById(“zeroconf2”).innerHTML=resp;
});
}
函数onLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
onLoad();
并将这一行放到config.xml
<gap:plugin name="cordova-zeroconf-plugin" source="npm" />
我的工作:
<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>
函数ondevicerady(){
ZeroConf.watch(“http.\tcp.local.”,函数(resp){
document.getElementById(“zeroconf2”).innerHTML=resp;
});
}
函数onLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
onLoad();
并将这一行放到config.xml
<gap:plugin name="cordova-zeroconf-plugin" source="npm" />