App doesn't broadcast when wakeLocks added - firefox-os

I have a geoLocation app for a Firefox OS device (ZTE Open v1.1), that broadcasts to a web server its location details.
However, my code doesn't run if I minimise the app and turn the screen off.
I thought adding the following requestWakeLocks to the code would sort the problem, but it doesn't seem to help:
var lock = window.navigator.requestWakeLock('gps');
var lock = window.navigator.requestWakeLock('wifi');
Do you have any idea what I am doing wrong?
Code:
function init() {
document.addEventListener("DOMContentLoaded", watchPosition, false); // to test on web browser
//document.addEventListener("deviceready", watchPosition, false); // deviceready is a cordova event
}
/* ---------------------------------- Local Variables ---------------------------------- */
var checkPeriodically;
var watchPositionOutput = document.getElementById('watchPositionOutput');
var ajaxVars; // HTTP POST data values
/* ---------------------------------- Local Functions ---------------------------------- */
function watchPosition() {
var lock = window.navigator.requestWakeLock('gps'); // FireFox-OS only - keeps the gps active when screen is off
var lock = window.navigator.requestWakeLock('wifi');
checkPeriodically = setInterval(checkTime, 10000);
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
var options = {
enableHighAccuracy: true,
}
function onSuccess(position) {
ajaxVars =
"lt=" + position.coords.latitude +
"&lg=" + position.coords.longitude +
"&ac=" + position.coords.accuracy +
"&sp=" + position.coords.speed +
"&ts=" + position.timestamp +
"&sec=SEC_TOKEN";
var dt = new Date(position.timestamp);
date_time =
dt.getFullYear() + '-' +
(dt.getMonth() + 1) + '-' +
dt.getDate() + ' ' +
dt.getHours() + ':' +
dt.getMinutes() + ':' +
dt.getSeconds();
watchPositionOutput.innerHTML =
'Latitude: ' + position.coords.latitude + '<br>' +
'Longitude: ' + position.coords.longitude + '<br>' +
'Accuracy: ' + position.coords.accuracy + '<br>' +
'Speed: ' + position.coords.speed + '<br>' +
'Timestamp: ' + date_time + '<br>';
}
function onError(error) {
watchPositionOutput.innerHTML = 'code: ' + error.code + '<br>' +'message: ' + error.message + '<br>';
}
}
// update the server with location data
function ajax_post(postData){
// when there is no data in postData
if (typeof(postData) === 'undefined') { return false; } // exit the function
var req = new XMLHttpRequest(); // Create XMLHttpRequest object
var url = "http://example.com/locate-me/post.php";
//var url = "http://localhost/locate-me/post.php";
req.open("POST", url, true);
// Set content type header info for sending url encoded variables in the request
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
var return_data = req.responseText; // return whatever php echos
var date_time = new Date(return_data * 1000); // php is currently returning the time (timestamp)
document.getElementById("status").innerHTML = "Server time: " + date_time;
}
}
// Send data to PHP, and wait for response to update the status div
req.send(postData); // execute the request
document.getElementById("status").innerHTML = "processing...";
}
// schedule to post the position data to a php script during certain times on certain days
function checkTime(){
// for example a day (day 0 == Sun) between 06:00 abd 23:45
var d = new Date();
var today = d.getDay();
var hms = d.getHours()+":"+d.getMinutes();
// mon - thurs
if( (today === 1 || today === 2 || today === 3 || today === 4) && hms > "10:23" && hms < "15:40") {
ajax_post(ajaxVars);
}
// friday
else if( today === 5 && hms > "13:00" && hms < "13:40") {
ajax_post(ajaxVars);
}
// testing: run all the time
else if( today < 7 ) {
ajax_post(ajaxVars);
}
else {
document.getElementById("status").innerHTML = "Data not scheduled to be posted to the server yet";
}
}
init();

Have you tried?
navigator.requestWakeLock('cpu');
If that still does not work, maybe you should follow the discussion in:
Firefox OS Background services

Related

Instagram Auto-Like JavaScript BOT

This code brings back an error of
Uncaught TypeError: Cannot read property 'innerHTML' of null
at doLike (<anonymous>:20:21)
at <anonymous>:35:1
doLike # VM1269:20
(anonymous) # VM1269:35
It has worked in the past, I got it from this website : https://blog.joeldare.com/simple-instagram-like-bot/
function getHeartElement() {
var knownHeartElementNames = ["coreSpriteHeartOpen", "coreSpriteLikeHeartOpen"];
var i = 0;
// Loop through the known heart elements until one works
for (i = 0; i < knownHeartElementNames.length; i++) {
var heartElement = document.querySelector("." + knownHeartElementNames[i]);
if (heartElement != undefined) {
break;
}
}
return heartElement;
}
function doLike() {
var likeMax = 100;
var likeElement = getHeartElement();
var nextElement = document.querySelector(".coreSpriteRightPaginationArrow");
likeCount++;
var nextTime = Math.random() * (14000 - 4000) + 4000;
if (likeElement.innerHTML.match("Unlike") == null) {
likeElement.click();
console.log(likeCount + " - liked");
} else {
console.log(likeCount + " - skipped");
}
setTimeout(function() {nextElement.click();}, 1000);
if (likeCount < likeMax) {
setTimeout(doLike, nextTime);
} else {
console.log("Nice! Time for a break.");
}
}
var likeCount = 0;
doLike();
You may want to use a tool such a Keygram - https://www.thekeygram.com
It works really well for me to gain followers

Detailed cooldown for commands

I saw in some discord servers that they have a detailed cooldown and that they can exactly see how long it takes before they can use that command again
but I don't know how add this, can someone help me?
I have this now
const talkedRecently = new Set();
if (talkedRecently.has(msg.author.id)) {
msg.channel.send("Wait 1 minute before getting typing this again. - " + msg.author);
} else {
talkedRecently.add(msg.author.id);
setTimeout(() => {
talkedRecently.delete(msg.author.id);
}, 60000);
}
but here you can't see exactly how long you have to wait. I want it like this:
If you create an object of cooldowns you can get how much time they would have left by subtracting the date from the cooldown.
Like so:
//Start of code or something
var cooldowns = {}
var minute = 60000;
var hour = minute * 24;
//Set cooldown
cooldowns[message.author.id] = Date.now() + hour * 24; //Set a 24 hour cooldown
//At command check
if(cooldowns[message.author.id]){
if(cooldowns[message.author.id] > Date.now()) delete cooldowns[message.author.id];
else console.log("user still has " + Math.round((cooldowns[message.author.id] - Date.now)/minute) + " minutes left"
}
I haven't tested it, but the simplest way to do this is something like:
const talkedRecently = new Set();
const seconds = "60";
loopnum = 0
while (loopnum <= seconds)) {
loopnum = loopnum + 1;
if (talkedRecently.has(msg.author.id + "-" + loopnum)) {
msg.channel.send("Wait **" + loopnum + " **seconds before getting typing this again. - " + msg.author);
return;
}
}
loopnum = seconds;
while (loopnum = 0) {
setTimeout(() => {
if (talkedRecently.has(msg.author.id + "-" + (loopnum+1))) {
talkedRecently.delete(msg.author.id "-" + (loopnum+1));
}
talkedRecently.add(msg.author.id + "-" + loopnum);
}, 1000);
loopnum = loopnum - 1;
}
if (talkedRecently.has(msg.author.id + "-1")) {
talkedRecently.delete(msg.author.id "-1");
}
return;

Client script not triggering when using "Add Multiple" Button on Sales Order (SuiteScript 1.0)

I have a client script which is doing two things:
Calculate total weight of sales order on add of line
Copy tax code from custom field to native field
The script deploys correctly when adding lines in the UI from the sublist but when using the "add multiple" button and selecting and adding multiple lines at once, the script does not trigger. Here is the script as I have it written so far (I have 2 versions, one which is validateLine and one which is postSourcing).
Validate Line:
function calculateTotalWeight(type){
var lines = nlapiGetLineItemCount('item');
var totalWeight = 0 ;
for(var i=1; i< lines+1 ; i++){
var weight = nlapiGetLineItemValue('item', 'custcol_itemweight', i);
var quantity = nlapiGetLineItemValue('item', 'quantity', i);
var weightTimesQuantity = weight * quantity;
totalWeight = totalWeight + weightTimesQuantity ;
}
nlapiSetFieldValue('custbody_items_total_weight', totalWeight);
}
function validateLine(type){
var taxableCustomer = nlapiGetFieldValue('custbody_taxable');
if (taxableCustomer == 'T'){
var customTax = nlapiGetCurrentLineItemValue(type,'custcol_taxcode');
nlapiLogExecution('DEBUG', 'Custom Tax Value',customTax);
nlapiSetCurrentLineItemValue('item','taxcode',customTax,true,true);
}
return true;
}
postSourcing:
function calculateTotalWeight(type){
var lines = nlapiGetLineItemCount('item');
var totalWeight = 0 ;
for(var i=1; i< lines+1 ; i++){
var weight = nlapiGetLineItemValue('item', 'custcol_itemweight', i);
var quantity = nlapiGetLineItemValue('item', 'quantity', i);
var weightTimesQuantity = weight * quantity;
totalWeight = totalWeight + weightTimesQuantity ;
}
nlapiSetFieldValue('custbody_items_total_weight', totalWeight);
}
function postSourcing(type, name)
{
if(type === 'item' && name === 'item')
{
var custcol_taxcode = nlapiGetCurrentLineItemValue('item', 'custcol_taxcode');
var line = nlapiGetCurrentLineItemIndex(type);
{
nlapiSetCurrentLineItemValue('item', 'taxcode', custcol_taxcode);
}
}
}
How can I get this script to trigger with the add multiple button?
You’ll need to calculate the weight on the recalc event. The following is from a script that works as a scriptable cart/checkout script. It can be deployed in an eCommerce context or the UI context. (i.e. a deployed client script as opposed to a client script attached to a form)
Note:You should set up your tax codes so that they are assigned automatically. It is possible to script those but it's a fair pain to do.
the field custbody_sco_toggle is a checkbox field that keeps the script out of an infinite loop if your recalc scripts might change the order total.
var scriptableCart = (function(){
var cartScript = {};
var isUI = ('userinterface' == nlapiGetContext().getExecutionContext());
var isWeb = !isUI;
function tty(type, title, detail){
var haveWindow = typeof window != 'undefined';
if(isUI && haveWindow && window.console) window.console.log(title, detail);
else if(isWeb || !haveWindow) nlapiLogExecution(type, title, (detail || '') +' '+entranceId +' '+nlapiGetContext().getExecutionContext()); // this slows down the NS GUI
}
function calculateTotalWeight(type){...}
cartScript.recalc = function(type){
tty("DEBUG", "entered "+ type +" with toggle: "+ nlapiGetFieldValue('custbody_sco_toggle'));
if('F' == nlapiGetFieldValue('custbody_sco_toggle')){
try{
nlapiSetFieldValue('custbody_sco_toggle', 'T', false, true);
if(type == 'item'){
calculateTotalWeight(type);
}
}catch(e){
tty('ERROR', 'In recalc for '+ type, (e.message || e.toString()) + (e.getStackTrace ? (' \n \n' + e.getStackTrace().join(' \n')) : ''));
}finally{
nlapiSetFieldValue('custbody_sco_toggle', 'F');
}
}
};
return cartScript;
})();

Asterisk 11 active calls event over AMI

Data I would like to have:
Num From , Num To , Duration, Codec, Context, Hold status
ofc in realtime update
I using node.js + nami
what the best way to get this information?
tried use an action Status(), but this gives me not full information about call and if I run it every second browser dies.
here is what I have:
updateCallList();
function updateCallList() {
socket.emit('GET_ACTIVE_CALLS', function(calls) {
$("#callsList").find("tr:gt(0)").remove();
if (calls.response != 'Success') return;
var calls = calls.events;
for (call in calls) {
if (calls[call].privilege == 'Call') {
var callFrom = calls[call].calleridnum + '<' + calls[call].calleridname + '>';
var callTo = calls[call].extension;
var callDuration = calls[call].seconds;
var callRoute = calls[call].context;
var tmpRow = '<tr>';
tmpRow = tmpRow + '<td>' + callFrom + '</td>';
tmpRow = tmpRow + '<td>' + callTo + '</td>';
tmpRow = tmpRow + '<td>' + callDuration + '</td>';
tmpRow = tmpRow + '<td>' + callRoute + '</td>';
tmpRow = tmpRow + '</tr>';
$('#callsList tr:last').after(tmpRow);
}
}
setInterval(function(){
updateCallList();
},1000);
});
}
server side
socket.on('GET_ACTIVE_CALLS', function (callback) {
action = new namiLib.Actions.Status();
nami.send(action, function (response) {
callback(response);
});
});
You need start daemon which will collect NewExten, Link, Unlink, Hangup events and create list of channels.
http://www.voip-info.org/wiki/view/asterisk+manager+events
Also you can do action command with "core show channels" "core show channel XXXXX", but asterisk will die if you do alot of that.
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Command

Node is not launching

I'm desperately trying to make node.js work again on Ubuntu 12.04 LTS.
I installed it before 2-3 weeks ago and everything went fine, I used it daily for that period of time.
But today, suddenly it just wouldn't work anymore. The way it bugs is really strange :
node -v works and returns v0.8.2
the node command works too, I can access the console and do a console.log
but when I use node with a file like this node server.js, Ubuntu just goes to a new line :
kollektiv#kollektiv-PC:~/node-projects$ node server.js
kollektiv#kollektiv-PC:~/node-projects$
I already reinstalled Ubuntu this evening but I get the same result.
I also did multiple apt-get upgrade and apt-get update in case some node.js dependencies would be out of date.
The way I installed node.js is by compiling the source following this tutorial : --> Compiling Node.js from source on Ubuntu 10.24 - shapeshed
I even did a chmod 777 server.js on the server file just to be sure but that didn't change anything either.
Thank you a lot in advance for your help !
EDIT : Content of server.js
var net = require('net'),
server = net.createServer();
var crypto = require('crypto'),
shasum = crypto.createHash('sha256');
var alpha = [],
i = 0,
cle = '';
while(i < 256) {
alpha.push(String.fromCharCode(i));
i++;
}
// CRYPTAGE -- START --
function cryptProcess(cle, txt) {
var k = txt.length,
j = k / cle.length,
cledeBase = cle,
txtc = '',
i = 1;
while(i < j) {
cle = cle + cledeBase;
i++;
}
function crypt(cleu, letr) {
//if(alpha.indexOf(letr) == -1) return "§";
var biIndex = alpha.indexOf(letr) + alpha.indexOf(cleu), x;
sumIndex = biIndex - alpha.length;
x = sumIndex >= 0 ? alpha[sumIndex] : alpha[biIndex];
return x;
}
while(k--) {
txtc = crypt(cle[k], txt[k]) + txtc;
}
return txtc;
}
function decryptProcess(cle, txtc) {
var k = txtc.length,
j = k / cle.length,
cledeBase = cle,
txt = '',
i = 1;
while(i < j) {
cle = cle + cledeBase;
i++;
}
txt = '';
function decrypt(cleu, letc) {
//if(alpha.indexOf(letc) == -1) return "§";
var biIndex = letc - alpha.indexOf(cleu), x;
x = biIndex >= 0 ? alpha[biIndex] : alpha[biIndex + alphabet.length];
return x;
}
while(k--) {
txt = decrypt(cle[k], txtc[k]) + txt;
}
return txt;
}
// CRYPTAGE -- END --
server.on('connection', function(client) {
var connecOne = 0;
function talk(data) {
var msg = data.toString('utf8');
var msgEnc = cryptProcess(cle, msg);
client.write(msgEnc);
console.log(msg + '\nsend as\n' + msgEnc);
}
client.once('data', function(data) {
function triHandShake() {
}
});
client.on('data', function(data) {
var msg = data.toString('utf8');
if(connecOne === 0) {
connectionOne(msg);
connecOne++;
}
else if(connecOne === 1) {
// Check for paragraph symbol
//authentification with cookie as cle
}
var msgDec = decryptProcess(cle, msg);
console.log(msgDec + '\nreiceved as\n' + msgDec);
});
client.on('end', function() {
connecOne = 0;
});
});
You need to call server.listen to listen for connections and start the process as expected.
server.listen(8124, function() { //'listening' listener
console.log('server bound');
});

Resources