Cannot read property 'udp' of undefined - google-chrome

I am trying to make a Chrome App to use UDP, but I can not pass simple UDP creation socket process. This is the error I get in the inspector window:
sockets.udp.create: TypeError: Cannot read property 'udp' of undefined
at Object.callback
The error is shown at this line:
chrome.sockets.udp.create({}, function(....
The manifest.json is this:
{
"manifest_version": 2,
"name" : "My App",
"description" : "My App Description",
"version" : "1.0",
"icons" : {
"16" : "icons/wl16.png",
"48" : "icons/wl48.png",
"128" : "icons/wl128.png"
},
"app" : {
"background" : {
"scripts": ["main.js"]
}
},
"sockets" : {
"udp" : {
"send" : ["*"],
"bind" : ["*"]
}
}
The main.js is as follows:
chrome.app.runtime.onLaunched.addListener(function() {
console.log('launched')
sendpack()
})
function sendpack() {
// Create the Socket
chrome.sockets.udp.create({}, function(socketInfo) {
// The socket is created, now we can send some data
var socketId = socketInfo.socketId;
chrome.socket.udp.bind(socketId, '127.0.0.1', 1345, function(result){
console.log('chrome.socket.bind: result = ' + result.toString());
});
var arrayBuffer=new ArrayBuffer(2);
arrayBuffer[0]=65;
arrayBuffer[1]=66;
chrome.sockets.udp.send(socketId, arrayBuffer,'127.0.0.1', 1337,function(sendInfo) {
console.log("sent " + sendInfo.bytesSent);
});
});
}
I copied everything from Chrome examples, but on the examples it works, on my app it doesnt.
If I print on the console the content of the object 'chrome.sockets.udp' it shows a valid object with 'create' method listed in it:
Object {onReceive: Event, onReceiveError: Event}
create: function()
What could be wrong?

I found the error, the bind call had bad object name:
chrome.socket.udp.bind
it should be in plural, "sockets"
chrome.sockets.udp.bind
I also mistakenly read the stack trace, from the bottom, not from the top.

Related

Binding Model in nodejs with express-cassandra

I just want to apply the Bind of the following tutorial and apply on my project:
http://express-cassandra.readthedocs.io/en/latest/usage/
My current model is on models directory called UserModel.js:
module.exports = {
fields:{
name : "text",
surname : "text",
age : "int",
created : "timestamp"
},
key:["name"]
}
And the index.js bind the last model:
var models = require('express-cassandra');
models.setDirectory( __dirname + '/models').bind(
{
clientOptions: {
contactPoints: ['127.0.0.1'],
protocolOptions: { port: 9042 },
keyspace: 'pop',
queryOptions: {consistency: models.consistencies.one}
},
ormOptions: {
defaultReplicationStrategy : {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'safe'
createKeyspace:true
}
},
function(err) {
if(err) throw err;
}
);
module.exports{
models:models
}
It goes Ok with the connection, but after the succesfull connect to casandra db(localhost:9042), It show me a message :"Keyspace user_schema does not exist"
Can anyone give me an idea to fix that? may be doesnt load the model, But It seems ok, But before to load the model It doesnt recognise the Keyspace, And It is the right Keyspace of my db
I updated the express-cassandra and now It Works, issue was the compatibility

Trying to use request with ES6 + Webpack, but I am getting an error

I am currently trying to create a webapp with React, and I am trying to make a request to my server (with request). However, whenever I try to webpack the app I get an error. I am almost certain it has to do with request having to be labeled as an external library, but I can't get it to work. Can anybody help me?
Here is my webpack config.
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin();
module.exports = {
entry : [
'./js/index.js'
],
output : {
path : __dirname + '/lib/',
publicPath : 'http://localhost:8080',
filename : 'bundle.js'
},
plugins : [
new ExtractTextPlugin('app.css'),
new webpack.NoErrorsPlugin()
],
module : {
loaders : [
{
test : /\.js$/,
loaders : [
'babel'
],
exclude : /node_modules/
},
{
test : /\.(jpe?g|png|gif|svg)$/i,
loaders : [
'url?limit=8192',
'img'
]
},
{
test : /\.scss$/,
include : /styles/,
loader : extractCSS.extract([
'css',
'autoprefixer',
'sass'
])
}
]
},
resolve : {
extensions : ['', '.js', '.json']
},
externals : {
request : 'request'
}
};
and here is the error that I am getting
ERROR in ./js/services/comic
Module parse failed: /Users/matthew.pfister/IdeaProjects/web/js/services/comic Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import request from 'request';
|
| export default {
# ./js/creators/comic.js 11:21-49
Here is the file it is referencing
import request from 'request';
export default {
...
};
I dont think export default {...} is valid. try
var o = {...}
export default o
should work.
I just realized that the file that is throwing the error doesn't have the .js extension.
::facepalm:: everything is fixed.

Java + Native messaging doesn't work good

I have a problem with Java application and Google Chrome due to NPAPI deprecation..
Reading some articles and blogs, I've found a "solution" : Native Messaging.
But all the examples were made in C++/C#/Python, and for Java there is nothing..
I would like if someone could help me with this..
Here's my schema (see image):
Google chrome Extension -> Native messaging -> Java App (jar)
Problem:
The extension calls the Java app, the Java app runs but doesn't receive anything and when it returns, nothing comes to extension.
Here's my code:
Chrome extension
background.js:
chrome.runtime.onConnect.addListener(function(port) {
port.onMessage.addListener(
function(message) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
console.log( 'background.js received msg [' + message.text + ']');
console.log( 'port.postMessage({content: "generated by background.js"}); to [' + tabs[0].id + "/" + tabs[0].url + ']');
chrome.runtime.sendNativeMessage('cnb.digitalsigning',message,function(response) {
console.log("Received from native " + response);
});
chrome.tabs.sendMessage(tabs[0].id, {content: "generated by background.js"});
});
return true;
});
port.onDisconnect.addListener(function() {
console.log("Background.js Port disconnected");
});
});
//native messaging
content_script.js
window.addEventListener("message", function(event) {
// We only accept messages from ourselves
if (event.source != window)
return;
if (event.data.type && (event.data.type == "DIGITAL_SIGNER_MSG")) {
console.log("Content script received from webpage: " + event.data.text);
console.log('calling port.postMessage(event.data.text); ...' + event.data.text );
port = chrome.runtime.connect();
port.postMessage({text: event.data.text});
}
}, false);
chrome.runtime.onMessage.addListener(
function(response, sender, sendResponse) {
alert("receiving response from extension" + response.content );
});
manifest.json
{
"name": "Test",
"description": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"persistent" : true,
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["content_script.js"]
}
],
"permissions": [
"nativeMessaging"
]
}
HTML
<html>
<script>
function myFunc(){
console.log('call func');
window.postMessage({ type: "DIGITAL_SIGNER_MSG", text: "do it, baby!" }, "*");
console.log('func called');
}
</script>
<body>
<div>Page</div>
<form>
<button id="caller" onclick="myFunc()">Call Extension</button>
<div id="reponseDiv" style="border: 3px; border-color: blue;">NO RESPONSE LOADED</div>
</form>
</body>
</html>
Host
installReg.bat
REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\digitalsigning" /ve /t REG_SZ /d "%~dp0digitalsigning.json" /f
pause
launch.bat
C:\location\to\Java\jre\bin\java.exe -cp C:\component\target\java.jar com.org.App
pause
digitalsigning.json
{
"name": "digitalsigning",
"description": "digitalsigning",
"path": "c:\\place\\launch.bat",
"type": "stdio",
"allowed_origins": [
"chrome-extension://<GOOGLE EXTENSION ID GENERATED>/"
]
}
The aplication contains a Main that captures the message using System.in.read and response to extension using System.out.write..
How could I do this communication?
Is this the correct way to start the java app?
At https://stackoverflow.com/a/25617143/865284 you can see how to send data in a proper way. System.in should be the correct way, but by now, i didn't find a way to receive data in java.
Note also this post, where sent and returned messages are sent successfully using only a few simple lines of code: https://stackoverflow.com/a/33113627. It should make it clear what the basic requirements of returned messages are.
You can take a look at https://github.com/Cosium/web-native-messaging-host .
It is a java library allowing to turn any JVM application into a Web Native Messaging Host .

Mailchimp batch subscribe error when using node-mailchimp API v2

I'm using the node-mailchimp wrapper for the MailChimp API v2.
I get the following error when calling 'batch-subscribe' or 'batch-unsubscribe' from a function:
-100 'You must specify a id value'
Here's the function:
function doBatchUnsub(theRequest)
{
api.call('lists', 'batch-unsubscribe', theRequest, function (error, data)
{
if (error)
{
errorMessage(error);
}
else
{
console.log(JSON.stringify(data));
}
}
);
}
It actually works fine if I paste the following JSON into the theRequest parameter:
{
"apikey" : "my-key-us8",
"id" : "my-id",
"batch" : [
{
"email" : "example#gmail.com"
},
{
"email" : "example#yahoo.com"
}
],
"delete_member" : true,
"send_goodbye" : false,
"send_notify" : false
}
I only get the error when I pass the JSON into the function from another function. When I do a console.log(theRequest) I can see the exact same text is getting sent to MailChimp. It's confusing.
Any ideas?

Sencha touch selectfield works fine in chrome, but it fails in android 2.1 emulator and Android 2.2 phone

I am learning Sencha Touch. I am having a strange issue. A view using select field is not showing it on Android emulator, but it does in Google Chrome. It worked fine before, I cannot guess what changed to "break" it.
In the emulator logcat I can see these three messages:
E/ActivityThread(243): Failed to find provider info for android.server.checkin
W/Checkin(243): Can't update stat BROWSER_SNAP_CENTER: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/stats
D/CordovaLog(243): undefined: Line 1 : TypeError: Result of expression 'c' [null] is not a constructor.
Sometimes only the third is shown.
Hereafter the view code:
(function() {
var setSettingValue = function(component, query, value) {
var c = component.query(query);
if (c && value && (c.length > 0)) {
c[0].setValue(value);
}
};
var createToolbar = function () {
return Ext.create('Ext.Toolbar', {
xtype: 'toolbar',
docked: 'bottom',
layout: { pack: 'center' },
items: [
{
iconMask: true, ui: 'normal', iconCls: 'info',
itemId: 'infoButton'
},
{ xtype: 'spacer' },
{
iconMask: true, ui: 'normal', iconCls: 'reply',
itemId: 'backButton'
}
]
})};
Ext.define('MyWF.view.Settings', {
extend: 'Ext.Container',
initialize: function ()
{
this.setItems([createToolbar()]);
this.callParent();
},
config : {
layout : 'vbox',
padding : '0 10',
scrollable: {
direction: 'vertical'
},
onBackAction: function () { console.log('back'); },
onInfoAction: function () { console.log('info'); },
listeners: [{
delegate: "#backButton",
event: 'tap',
fn: 'onBackAction'
},
{
delegate: "#infoButton",
event: 'tap',
fn: 'onInfoAction'
},
{
event: 'show',
fn: function(component, eOpts) {
setSettingValue(component, 'selectfield[name=windMU]','kmh');
setSettingValue(component,'selectfield[name=temperatureMU]','C');
}
}],
items : [{
xtype : 'fieldset',
title : 'Measure units',
items : [{
xtype : 'selectfield',
name : 'temperatureMU',
label : 'Temperature',
labelAlign: 'top',
listeners : {
change : function(selectField, newData, oldData, eOpts) {
alert('Your choice is: ' + newData);
}
},
options : [{
text : 'Celsius',
value : 'C'
}, {
text : 'Farenheit',
value : 'F'
},]
}, {
xtype : 'selectfield',
name : 'windMU',
label : 'Wind speed',
labelAlign : 'top',
listeners : {
change : function(selectField, newData, oldData, eOpts) {
alert('Your choice is: ' + newData);
}
},
options : [{
text : 'Kilometers per hour',
value : 'km/h'
}, {
text : 'Meters per second',
value : 'm/s'
}, {
text : 'Miles per hour',
value : 'MPH'
}, {
text : 'Knots',
value : 'kn'
}]
}]
},]
}
});
})();
Thanks for any suggestion
Well I got some time to fix the issue.
First of all I add a lacking information to the question: I was running the app with a custom build of the Sencha Touch library, the library version is 2.0.1.1.
On Google Chrome the select field (Ext.field.Select) creates by default an Ext.dataview.List instance for the list of choiches, while on a phone an Ext.picker.Picker is created.
But Ext.picker.Picker also creates an Ext.TitleBar, that was lacking in my custom build of sencha library, while the Ext.dataview.List class is in.
So the application can show the select field in Chrome, but it cannot in the emulator, and it gives the unclear message, because the libary build is compressed and obfuscated.
There are two solutions:
you can force the use of a list also in the emulator or phone. The class Ext.picker.Picker has a creation option for this: "usePicker: false", by default set to "auto".
or, better, add an explicit reference to the title bar component in the app file: "Ext.require('Ext.TitleBar');" to include it in the library build.
I saw the problem forcing the use of the picker in Chrome, by setting the picker configuration "usePicker: true", and running the app with the debug library build "sencha-touch-debug.js", see http://docs.sencha.com/touch/2-0/#!/api/Ext.Loader, and http://docs.sencha.com/touch/2-0/#!/guide/building .
Then in the Chrome console, as well in the Android emulator logcat, I saw the clear message:
[WARN][Anonymous] [Ext.Loader] Synchronously loading 'Ext.TitleBar';
consider adding 'Ext.TitleBar' explicitly as a require of the corresponding class
A suggestion: in the logcat is better to filter the many messages, for example writing "Ext.Loader" in the filter mask.