Add auto refreshing token code brrp. Also testing

This commit is contained in:
Christopher Cookman 2024-03-23 13:26:59 -06:00
parent d193652df1
commit eaf370c0a0
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -10,13 +10,23 @@ const {
FreepbxGqlClient,
gql
} = require("freepbx-graphql-client");
const pbxClient = new FreepbxGqlClient(config.freepbx.url, {
var pbxClient = new FreepbxGqlClient(config.freepbx.url, {
client: {
id: config.freepbx.clientid,
secret: config.freepbx.secret,
}
});
// 50 minute interval to refresh the token
setInterval(() => {
pbxClient = new FreepbxGqlClient(config.freepbx.url, {
client: {
id: config.freepbx.clientid,
secret: config.freepbx.secret,
}
});
}, 3000000);
// Set up mariadb connection
const mariadb = require('mariadb');
const pool = mariadb.createPool(config.mariadb);
@ -25,6 +35,31 @@ const cdrPool = mariadb.createPool(config.cdrdb);
// Some functions for FreePBX
const reload = () => {
// We're gonna start converting all the old gql commands to using mysql `system fwconsole reload` query
return new Promise((resolve, reject) => {
// DB connection
var conn = pool.getConnection();
conn.then((conn) => {
conn.query("system fwconsole reload").then((result) => {
resolve(result);
}).catch((error) => {
reject(error);
});
conn.end();
}).catch((error) => {
reject(error);
})
});
}
console.log("Reloading PBX")
reload().then((result) => {
console.log("Reloaded PBX")
}).catch((error) => {
console.log("Error reloading PBX")
});
const getExtCount = () => {
return new Promise((resolve, reject) => {
pbxClient.request(funcs.minifyQuery(funcs.generateQuery('list', {}))).then((result) => {