Cordova plugins undefined

I am trying to use the ZeroConf plugin for Cordoba. I have never used the Cordoba plugin before.

These are the steps I took:

cordova create myApp
cordova platform add android
cordova platform add ios
cordova platform add browser
cordova plugins add https://github.com/cambiocreative/cordova-plugin-zeroconf

Subsequently, I changed the default function onDeviceReadyso that the index.js file (in the directory myApp/www/) looked like this:

var app = {
    ...

    onDeviceReady: function() {
        app.receivedEvent('deviceready');

        if(cordova && cordova.plugins) {
            console.log('cordova.plugins is available');
        } else {
            console.log('cordova.plugins NOT available');
        }
    },

    ...
};

app.initialize();

Unfortunately, it always registers "cordova.plugins NOT available". I first checked to see if it exists cordova, but it is cordova.pluginsundefined. Note that I am testing this in the browser ( cordova run browser) to find the problem as soon as there cordova.pluginsis no more undefined. I can use the ZeroConf plugin.

I searched for watches, read many similar topics, but no one could help me.

What I tried:

  • cordova plugin ls → ZeroConf plugin is present com.cambiocreative.cordova.plugin.zeroconf 1.0.9 "Cordova ZeroConf Plugin"

  • , index.html cordova.js script

  • config.xml ( myApp/www/config.xml) <plugin name="com.cambiocreative.cordova.plugin.zeroconf" version="1" />, . <feature name="ZeroConf"><param name="android-package" value="com.cambiocreative.cordova.plugin.ZeroConf" /><param name="onload" value="true" /></feature> .

, index.html ( myApp/www/index.html):

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>

EDIT: ZeroConf "zeroconf.js" .

onDeviceReady:

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    var el = document.getElementById("zcOK");

    if(typeof ZeroConf !== 'undefined') {
        el.innerHTML = "ZEROCONF READY";
    } else {
        el.innerHTML = "ZEROCONF NOT READY";
    } 
}

"ZEROCONF NOT READY"...

( id="zcOK", ).

<p id="zcOK">ZeroConf test</p>
<!-- ORDER IN WHICH THE SCRIPTS ARE LOADED -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="../plugins/com.cambiocreative.cordova.plugin.zeroconf/www/zeroconf.js"></script>
<script type="text/javascript" src="js/index.js"></script> <!-- Contains the onDeviceReady function -->

, "ZeroConf" undefined, , "index.js", "index.html"?

+4
2

config.xml JS of cordova-plugin-zeroconf :

<js-module src="www/zeroconf.js" name="ZeroConf">
    <clobbers target="cambiocreative.CDVZeroConfig" />
</js-module>

, API- : cambiocreative.CDVZeroConfig

Cordova:

... <js-module>:

<clobbers target="some.value"/> , module.exports window.some.value. <clobbers>, . , , ....

+2

, , , cordova.plugin. , .

+1

Source: https://habr.com/ru/post/1628858/


All Articles