我想使用此cordova插件来使用mDNS: https://github.com/stevenpack/phonegap-multicastdns
但是没有示例代码或指南,而且我对angularJS和Ionic都很新。那么如何使用这个插件?以及如何从插件代码中获取它?
这是我到目前为止所得到的:
添加了插件:
cordova plugin add https://github.com/stevenpack/phonegap-multicastdns.git
一切正常,我现在有一个" plugins / com.koalasafe.cordova.plugin.multicastdns"夹。
现在我想我需要将它包含在我的控制器中并使用这些功能?
答案 0 :(得分:0)
您可以通过以下方式在角度代码中使用
MulticastDNSPlugin.query(host, multicastIP, port, successCallback, errorCallback)
如需更多帮助,请在作者源目录here上创建问题,并了解自定义插件的流程,请参阅此link
希望这会对你有帮助!
答案 1 :(得分:0)
首先,首选ionic
而不是cordova
。大多数离子只是遵循底层的cordova命令,但有时它会做更多,例如维护packages.json。所以:
ionic plugin add https://github.com/stevenpack/phonegap-multicastdns.git
现在你应该有一个/plugins/com.koalasafe.cordova.plugin.multicastdns
文件夹。
你的package.json应该有类似的东西:
"cordovaPlugins": [
{
"locator": "https://github.com/stevenpack/phonegap-multicastdns",
"id": "com.koalasafe.cordova.plugin.multicastdns"
},
你可以这样打电话:
$window.multicastDNS.query("some host", "224.0.0.251", 5353, function (data) {
$log.info("MulticastDNS query success.Callback data: " + data);
}, function (reason) {
$log.error("MulticastDNS query failed: " + reason);
});