vstirbu / ZeroConf

ZeroConf plugin for Cordova/Phonegap 3.0
MIT License
38 stars 21 forks source link

missing exec:ZeroConf.watch #11

Closed drasko closed 9 years ago

drasko commented 9 years ago

Hi, I am trying ZeroConf plugin with simple lines:

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

        ZeroConf.watch('_http._tcp.local.', function(result) {
           // do something with the result
           console.log("RESULT: " + result);
        });

        ZeroConf.list('_http._tcp.local.', 1000, function(resultArray) {
          alert("Scanned " + resultArray[0] + " code: " + resultArray[1]);
        }, function(error) {
          alert("Failed: " + error);
        });
    },

What I am getting is something like ZeroConf can not be found by Cordova:

Console was cleared
ripple.js:37 Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.)
http://localhost:4400/ripple/assets/ripple.js Failed to load resource: the server responded with a status of 404 (Not Found)
ripple.js:37 cordova :: Initialization Finished (Make it so.)
localhost/:26 The key "target-densitydpi" is not supported.
index.js:58 Received Event: deviceready
ripple.js:40 missing exec:ZeroConf.watch
ripple.js:40 Array[1]
ripple.js:40 TypeError: Cannot read property 'watch' of undefined
ripple.js:40 TypeError: Cannot read property 'watch' of undefined
    at module.exports.exec (http://localhost:4400/ripple/assets/ripple.js:40:28665)
    at Object.ZeroConf.watch (http://localhost:4400/plugins/com.triggertrap.ZeroConf/www/ZeroConf.js:20:10)
    at app.onDeviceReady (http://localhost:4400/js/index.js:38:18)
    at Channel.fire (http://localhost:4400/cordova.js:806:23)
    at http://localhost:4400/cordova.js:224:49
ripple.js:48 ZeroConf
ripple.js:48 watch
ripple.js:40 missing exec:ZeroConf.list
ripple.js:40 Array[2]
ripple.js:40 TypeError: Cannot read property 'list' of undefined
ripple.js:40 TypeError: Cannot read property 'list' of undefined
    at module.exports.exec (http://localhost:4400/ripple/assets/ripple.js:40:28665)
    at Object.ZeroConf.list (http://localhost:4400/plugins/com.triggertrap.ZeroConf/www/ZeroConf.js:44:24)
    at app.onDeviceReady (http://localhost:4400/js/index.js:43:18)
    at Channel.fire (http://localhost:4400/cordova.js:806:23)
    at http://localhost:4400/cordova.js:224:49
ripple.js:48 ZeroConf
ripple.js:48 list
vstirbu commented 9 years ago

Just to make it sure, the plugin is installed using the cordova-cli tool, right?

Can you also post some details about your environment (e.g. Cordova version). Thanks!

drasko commented 9 years ago

Yes, using Cordova CLI.

I am using most recent Cordova, freshly installed with npm -g install cordova. I guess it is version v4.2.0.

Are you sure that ZeroConf is included right after installation with CLI? I never wrote something like require('ZeroConf'), I just start using it straight away, as you suggested. Here: https://github.com/phonegap/phonegap-plugins/wiki/Defining-Your-Cordova-Plugin-As-A-Cordova-Module I can see that some require is needed. Is this the case for ZeroConf also?

vstirbu commented 9 years ago

I have tested the plugin only with Cordova 3.x. Have to check if something changed since

drasko commented 9 years ago

Hello, actually this code:

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

        ZeroConf.watch('_http._tcp.local.', function(result) {
           // do something with the result
           console.log("Service name: " + result.service.name);
        });
    }

works fine on device, Nexus5 phone, built with Cordova v4.2.0

ripple emulate however expects to give it JSON structure on the input, in the prompt form. I copy-pasted JSON example from your README.md and it worked.

I had one error before, like this: http://stackoverflow.com/questions/26015733/uncaught-syntaxerror-unexpected-token-o-json-parse, trying to JSON.parse(result), not understanding that it was already a parsed object.

You can close the issue.

vstirbu commented 9 years ago

Glad to see that you made it work.

On the JSON input, the communication between the native side and JavaScript is implemented using strings. So, it you pass objects they have to be serialized to JSON.