How to use custom Cordova plugin?

I want to use this cordova plugin to use mDNS:

But there is no example code or guides, and I am quite new to angularJS and Ionic. So how to use this plugin? and how can I derive that from the plugin code?

This is what I’ve got so far:

Added the plugin:

cordova plugin add

It went ok and I now have a “plugins/com.koalasafe.cordova.plugin.multicastdns” folder.

Now I guess I will need to include it to my controller and use the functions?

When you got no documentation, you have to open the plugin file and see what’s implemented.

In the plugin.xml file, you can see there is a <clobbers target="multicastDNS" /> tag, which means this will be the global JS variable the plugin will rely on.

After that, you open the actual .js file to see the exported methods:

module.exports = {
query: ... 

So, there will be a global object named multicastDNS with a query method in it.

Just call multicastDNS.query(host, multicastIP, port, successCallback, errorCallback); from your controller.

BTW, because the plugin is not documented nor tested, I believe it’s not even working as expected.

1 Like