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
Related
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;
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
Cisar verifies the jslink is getting called correctly but rendering only happens when I open the file with the cisar inspector. Weird.
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Header = "<div class='row'><div class='col-md- 8'>Title</div><div class='col-md-1'>Screen 16x9</div><div class='col-md-1'>Print</div><div class='col-md-2'>Updated</div>";
overrideCtx.Templates.Footer = "</div>";
overrideCtx.Templates.Item = CustomItem;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function CustomItem(ctx) {
// Build a listitem entry for every announcement in the list.
var ret = "<div class='col-md-8'>" + ctx.CurrentItem.Title + "</div><div class='col-md-1'><a href='https://domain/subsite/library/" + ctx.CurrentItem.FileLeafRef + "'><i class='fa fa-tv fa-2x'></i></a></div><div class='col-md-1'><a href='" + ctx.CurrentItem.Print_x0020_4x3 + "'><i class='fa fa-print fa-2x'></i></a> </div>" "<div class='col-md-2'>" + ctx.CurrentItem.Updated + " </div>"
;
return ret;
}
Let's say I want to find all user playlists that include the track 'Roygbiv' by Boards of Canada. Is it possible to modify the function below to make this happen?
var mySearch = Search.search('Roygbiv');
mySearch.playlists.snapshot().done(function(p){
searchPlaylists.innerHTML = '<h4>Playlists (' + p.length + ')</h4>';
var playlistsResults = [];
for (var i = 0, l = Math.min(p.range.length, maxResults); i < l; i++) {
playlistsResults.push('' + p.get(i).name + '');
}
searchPlaylists.innerHTML += '<p>' + playlistsResults.join(', ') + '...</p>';
});
I am pretty new to nodejs.
What I want my code to do it to query a database a number of times, collect data from all the queries in one variable and then use it somewhere.
But I guess nodejs instead of waiting for the result of the queries, execute without blocking.
This is what I think is happening. Sorry if I am wrong.
for (var i = step_min; i < (step_max); i += step) {
query = 'select count(' + colName + ') as num_count from ' +
rows[0].tablename + ' where ' + 'dictionaryid=' +
rows[0].dictionaryid + ' and ' + colName + ' between ' + i +
' and ' + (i + step);
connection.query(query, function(err, rows1, fields) {
if (err) {
console.log(err);
throw err;
}
try {
console.log("$$$$$$$$$$$$$$$ pushed : "+ rows1[0].num_count);
contents.push(rows1[0].num_count);
console.log('contents : '+ contents+'\n');
} catch (e) {
if (e instanceof SyntaxError) {
console.log("Syntax Error for input function");
}
}
});
console.log("##################### " + query + "\n");
console.log('contents : '+ contents+'\n');
}
Any advice either on how to block nodejs till the result from query is obtained or otherwise a way to restructure my code ?
Thanks in advance.
You are correct that it is not waiting for your queries before executing. You can look at the node-mysql-queues module which you can use to queue queries, and execute the given callback after all have executed (it will also allow you do perform transactions)
Another (hack) approach is to set a counter of the number of queries you are executing. In the callback of each transaction save the result into your return object and decrement the counter. If it is <= 0 then all your queries have completed, and you can execute your main callback with the return object.
Also, watch out for SQL injection.
try this:
https://github.com/luciotato/waitfor
your code with wait.for:
for (var i = step_min; i < (step_max); i += step) {
query = 'select count(' + colName + ') as num_count from ' +
rows[0].tablename + ' where ' + 'dictionaryid=' +
rows[0].dictionaryid + ' and ' + colName + ' between ' + i +
' and ' + (i + step);
var rows1 = wait.forMethod(connection,"query",query); //waits until callback
console.log("$$$$$$$$$$$$$$$ pushed : "+ rows1[0].num_count);
contents.push(rows1[0].num_count);
}
console.log("##################### " + query + "\n");
console.log('contents : '+ contents+'\n');
} catch (e) {
if (e instanceof SyntaxError) {
console.log("Syntax Error for input function");
}
....
}
Doing something like below could be a work around.
//Its just a test code whatever came to mind first so I'll tune it later...
var contents = [];
var lock = 0;
for (var i = step_min; i < (step_max + step); i += step) {
lock++;
}
for (var i = step_min; i < (step_max + step); i += step) {
query = 'select count(' + colName + ') as num_count from ' + rows[0].tablename + ' where ' + 'dictionaryid=' + rows[0].dictionaryid + ' and ' + colName + ' between ' + i + ' and ' + (i + step);
connection.query(query, function(err, rows1, fields) {
if (err) {
console.log(err);
throw err;
}
try {
console.log("$$$$$$$$$$$$$$$ pushed : " + rows1[0].num_count);
contents.push(rows1[0].num_count);
console.log('contents : ' + contents + '\n');
} catch (e) {
if (e instanceof SyntaxError) {
console.log("Syntax Error for input function");
}
}
lock--;
if (lock == 0) {
queryDone();
}
});
}
function queryDone() {
console.log("##################### " + query + "\n");
console.log('contents : ' + contents + '\n');
var id = obj.exptID + '.' + obj.exptITR + '.' + obj.nodeID + '.' + obj.resourceName + '.' + colName;
serie = {
name: colName,
data: contents,
id: id
};
console.log("--------------------\n " + step_max + "\n" + step_min + "\n------------------------\n");
}
The approach is to fire a function when all queries are done as Nick said...