Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

cordova app chrome not defined #8

Open
wlzimmer opened this issue Feb 8, 2016 · 2 comments
Open

cordova app chrome not defined #8

wlzimmer opened this issue Feb 8, 2016 · 2 comments

Comments

@wlzimmer
Copy link

wlzimmer commented Feb 8, 2016

I installed the plugin in Cordova with
cordova plugin add https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp

and when the app runs I get a message chrome not defined.

What am I missing?

@wlzimmer
Copy link
Author

wlzimmer commented Feb 9, 2016

As a followup, the calls to chrome.sockets... were in a onDeviceReady function; Code as follows

var app = {
sendTo: function (data, addr, port) {
alert ("sendTo");
chrome.sockets.udp.create(function(createInfo) {
chrome.sockets.udp.bind(createInfo.socketId, '0.0.0.0', 0, function(result) {
chrome.sockets.udp.send(createInfo.socketId, data, addr, port, function(result) {
if (result < 0) {
alert('send fail: ' + result);
chrome.sockets.udp.close(createInfo.socketId);
} else {
alert('sendTo: success ' + port);
chrome.sockets.udp.close(createInfo.socketId);
}
});
});
});
},

receiveErrorListener: function (info) {
alert ('RecvError on socket: ' + info.socketId);
chrome.sockets.udp.close(info.socketId);
},

receiveListener: function (info) {
var listItem = document.createElement('li');
var html = '' + info + '';
listItem.innerHTML = html;
deviceList.appendChild(listItem);
chrome.sockets.udp.close(info.socketId);
},

addReceiveListeners: function () {
try{
alert("Add Listeners");
alert (typeof(chrome) == "undefined");
chrome.sockets.udp.onReceiveError.addListener(this.receiveErrorListener);
alert("add listeners 2");
chrome.sockets.udp.onReceive.addListener(this.receiveListener);
} catch(err) {alert(err);}
},

initialize: function() {
    this.bindEvents();
    detailPage.hidden = true;
},

bindEvents: function() {
    alert("bind");
    document.addEventListener('deviceready', this.onDeviceReady, false);
},

onDeviceReady: function() {

alert (typeof(chrome) == "undefined");
alert("ready");
try {
app.addReceiveListeners();
app.sendTo ("Discover,0,", "255.255.255.255", 12345);
alert ("Send Discover");
} catch(err) {alert(err);}
},

onError: function(reason) {
    alert(reason); 
}    

};

@wlzimmer
Copy link
Author

wlzimmer commented Feb 9, 2016

Problem fixed by upgrading to Cordova v 6.0

yvni added a commit to yvni/cordova-plugin-chrome-apps-sockets-udp that referenced this issue Apr 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant