JSJaC + Openfire: no connection with some users - javascript

ok, I'm finally at my wits' end. I have a have an XMPP server (Openfire) running, and trying to connect via JavaScript using JSJaC. The strange thing is that I can establish a connection for some users, but not for all. I can reproduce the following behavior: create two accounts (username/password), namely r/pwd and rr/pwd with the result:
r/pwd works
rr/pwd doesn't work.
So far, each account with a user name consisting of only one character works. This is strange enough. On the other side, old accounts, e.g., alice/a work. The whole connection problem is quite new, and I cannot trace it to any changes I've made.
And to make my confusion complete with any instant messenger supporting XMPP, all accounts work, incl., e.g., rr/pwd. So assume, the error must be somewhere in my JavaScript code. Here's he relevant snippet:
...
oArgs = new Object();
oArgs.domain = this.server;
oArgs.resource = this.resource;
oArgs.username = "r";
oArgs.pass = "pwd";
this.connection.connect(oArgs);
The code above works, but setting oArgs.username = "rr", and it fails.
I would be grateful for any hints. I'm quite sure that it must be something really stupid I miss here.
Christian

Adding oArgs.authtype = 'nonsasl' to the argument list when creating the xmpp connection using JSJaC solved my problem. I haven't tried Joe's command to alter the SASL settings in Openfire; I'm scared to ruing my running system :).

Related

Occasional (404) Not Found, for SpreadsheetsService.Query

I use Spreadsheet API to update sheets.
At some quite rare, and random, times the SpreadsheetsService.Query returns a (404) Not Found.
It is not just because there is not internet, or the service is down, because when it happens it keep happening for this specific query but not others.
It is quite weird :) Let me know if anyone has any hints.
The code is posted here below.
var requestFactory = new GDataRequestFactory("Some Name");
requestFactory.CustomHeaders.Add(string.Format("Authorization: Bearer {0}", credential.Token.AccessToken));
SpreadsheetsService service = new SpreadsheetsService("{my name}");
service.RequestFactory = requestFactory;
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = service.Query(query); //here comes the exception.
SpreadsheetEntry spreadsheet = null;
gdata is the older version of Sheets API and it's shut down. See Google's announcement here https://cloud.google.com/blog/products/g-suite/migrate-your-apps-use-latest-sheets-api
Whats happened what that I had actually upgraded everything to V4, but then it is normal very rarely to get 404s, and off course you need to retry after a timeout.
In my case I was still using the old API in the retries and so the 404 never got saved.

No ACK recieved in Gun.js

I am using Gun.js and on load I am putting a value in.
This is for a new website, and I have already tried making everything when the page loads instead of just in a script tag.
var mid = Date.now().toString() + "and" + (Math.round(Math.random()) + Math.round(Math.random())).toString();
var gun = Gun('https://gunjs.herokuapp.com/gun');
gun.get(`tictac/toe${mid}`).put({
"type": "test"
});
I expect it not to produce an error, but it is producing an error:
{err: "Error: No ACK received yet.", lack: true}
I don't know what to do.
#Mikey ,
No ACK received yet lack: true means that GUN has not received an acknowledgement that the data was correctly saved. This means your data may not be backed up.
Often times this happens because on other peers someone is running GUN as require('gun/gun') which does NOT include default storage adapters. On other (non-browser) peers, you should include GUN as require('gun') which DOES include default adapters (transport, storage, etc.).
In this case, it looks like you are connected to a testing peer (gunjs.herokuapp), please note that this is not for production use cases, and could be part of the problem.
For us to figure out what is going wrong, I highly encourage you to join our super friendly community ( https://gitter.im/amark/gun ) to help you out.

Elegant way of harnessing facebook ads data without api

I was helping one of my relatives with a Facebook campaign for their store.The campaign was a success as we gathered about more than 1000 new likes and a lot of queries.They were happy but I really wanted to do some more with that data like tag those people who liked if their setting allowed or send a message on messenger for arrival of new items.In short keep a track of the all that was happening.The idea is to harness the data so that maximum can be achieved next time on similar campaigns.
I wanted a something simple so that the guys at the store can do it themselves without any fiddling with api.After some trial and error i came up with this js code which can be pasted into console after opening the window which appears when you click link just on the side of like button.
/*a script to get all the people who liked the page
after a facebook campaign. A successful capmpaign will get 1000's of
likes so it will be impossible to load all the names in one go.Also the
list loads progressively with each scroll. So
the code introduces a last element in the json which you have to put in
place of "i" in the given code when you press see more button in
subsequent runs.On my fairly powerful laptop and decent internet I was
not able to get more than 350 persons without a good lag.
The value of i is calculated by trial and error as the data attributes `
before that holds something else(not required) and not the names.I hope
it will be more or less similar in all of them.
This code is to be pasted in the console once the window with all the
likes is opened.*/
var arrayName = document.querySelectorAll('[data-gt]');
var PersonObject={};
try {
for(var i = 55;i<=arrayName.length;i++ ){
var element=arrayName[i];
console.log(element);
var name=element.innerHTML;
// console.log(i)
PersonObject[("name"+i)]=name;
// console.log(PersonObject)
}
}
catch(error){
console.log("error occured at"+i)
}
finally{
PersonObject["lastElement"]=i;
var NamesJson = JSON.stringify(PersonObject)
console.log(NamesJson)
}
I tried to write the gist of code in comments.
Now my real question,this all seems so hacky and patched stuff but not elegant. Isn't there a way for business owners to actually harness this data in more systematic way without the need for any api's or any programming knowledge?

Server-side Javascript functions

Ok guys. I've built a web application with some friends that is somehow complex and took us some time to built. It is entirely built using JavaScript
Now the application has some functions which we don't want to readily share with the world(view-source).
The application works by sending an input to an algorithm and receiving the output from that algorithm and displays it on a canvas. (Thats how all functions work anyway:) )
Okay i don't know much about node.js but from what i've heard its server-side JavaScript. Does that mean that i can transfer the function server-side and using POST-GET to send an input and receive an output? All without having the source code of that particular function readily visible to anyone?
Please don't get started about how i should be more worried about doing things better rather than worrying about the safety of our work. I already know that so consider my question as a complimentary safeguard, at least for the time being.
Obfuscation is not a very concrete option since many developers de-obfuscate code just for fun.
This application is not like a hen with a golden egg and i am not being grandiose about this, but i was just having this question in my mind for some time now so i just shoot it here to know in the future how things work.
Thanks guys!
If you're worried about protecting your ultra sweet super secret codes, you could host your app and use a little something called RPC. Remote. Procedure. Calls.
Check out this little guy
https://github.com/deoxxa/pillion
Easy as 1-2-3 or A-B-C or cake or strippers or whatever else is easy
% npm install pillion burro && echo omg that was so easy
DISCLAIMER
I'm about to reveal a super secret greeting function that says hello to our clients. This is ultra secret intellectual IP properties and should not be shared with anyone on the internets.
You could provide the function calls you need using something like this on the server
// server.js
var net = require("net"),
burro = require("burro"),
pillion = require("pillion");
var server = net.createServer(function(_socket) {
var socket = burro.wrap(_socket),
rpc = new pillion(socket);
rpc.provide("greet", function(name, cb) {
cb("hi there, " + name);
});
});
server.listen(3000);
Then on the client side
// client.js
var net = require("net"),
burro = require("burro"),
pillion = require("pillion");
var _socket = net.connect(3000),
socket = burro.wrap(_socket),
rpc = new pillion(socket);
rpc.callRemote("greet", "friend", function(res) {
console.log(res); // prints "hi there, friend"
});

Disconnect node-xmpp client

I am looking at node-xmpp and node-simple-xmpp and I am trying to make a simple client.
Everything works fine, except the disconnect.
I have made the following file after the example of simple-xmpp:
var xmpp = require('simple-xmpp');
xmpp.on('online', function() {
console.log('Yes, I\'m connected!');
xmpp.send('test2#example.com', 'Hello test');
// OK UNTIL HERE, DISCONNECT NOW
});
xmpp.connect({jid: 'test#example.com/webchat', password: 'test', reconnect: 'false'});
But I don't know how to disconnect. I tried to send a stanza with unavailable type:
stanza = new xmpp.Element('presence', {from: 'test#example.com', type: 'unavailable'});
xmpp.conn.send(stanza);
delete xmpp;
This is causing the client to go temporarily offline, but the problem is, it reconnects after a few seconds and keeps sending 'presence' stanza.
I have also tried calling xmpp.conn.end(), which also disconnects but it gives an error afterwards:
node_modules/simple-xmpp/node_modules/node-xmpp/lib/xmpp/connection.js:100
if (!this.socket.writable) {
^
TypeError: Cannot read property 'writable' of undefined
So, what am I doing wrong? I am sure there is an easy way to disconnect.
In the first case, <presence type='unavailable'/> does not always actually disconnect you; in your server, it looks like it might be, but your client is auto-reconnecting. delete xmpp is not actually causing your object to be cleaned up, it's just removing it from the local namespace.
In the second case send() isn't writing your stanza to the underlying socket immediately. If you close the socket with end() right afterwards, the socket is closed when the write actually happens.
If you add a short timeout after you call send(), before calling end() it will work. To make it good, you'll want your library developers to give you a callback when send() has actually written to the socket.
You should also check this out https://www.rfc-editor.org/rfc/rfc7395
In short if client is using to open connection it should use to kill that same connection.
To be more precise:
<close xmlns="urn:ietf:params:xml:ns:xmpp-framing" />
Solution of "Joe Hildebrand" also solved my problem, but this seemed more proper way for me.

Categories