Add auto refreshing token code brrp. Also testing
This commit is contained in:
parent
d193652df1
commit
eaf370c0a0
37
index.js
37
index.js
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue