mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
Remove callback support and global Gamedig.debug option
This commit is contained in:
parent
fdc08b5c09
commit
dfa5c95efc
5 changed files with 28 additions and 46 deletions
35
lib/index.js
35
lib/index.js
|
|
@ -1,48 +1,23 @@
|
|||
const QueryRunner = require('./QueryRunner'),
|
||||
GlobalUdpSocket = require('./GlobalUdpSocket');
|
||||
const QueryRunner = require('./QueryRunner');
|
||||
|
||||
let singleton = null;
|
||||
|
||||
class Gamedig {
|
||||
constructor() {
|
||||
this.udpSocket = new GlobalUdpSocket();
|
||||
this.queryRunner = new QueryRunner(this.udpSocket);
|
||||
this._debug = false;
|
||||
}
|
||||
|
||||
setDebug(on) {
|
||||
this.udpSocket.debug = on;
|
||||
this._debug = on;
|
||||
this.queryRunner.debug = on;
|
||||
this.queryRunner = new QueryRunner();
|
||||
}
|
||||
|
||||
async query(userOptions) {
|
||||
userOptions.debug |= this._debug;
|
||||
return await this.queryRunner.run(userOptions);
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (!singleton) {
|
||||
singleton = new Gamedig();
|
||||
}
|
||||
if (!singleton) singleton = new Gamedig();
|
||||
return singleton;
|
||||
}
|
||||
static query(userOptions, callback) {
|
||||
const promise = Gamedig.getInstance().query(userOptions);
|
||||
if (callback && callback instanceof Function) {
|
||||
if (callback.length === 2) {
|
||||
promise
|
||||
.then((state) => callback(null, state))
|
||||
.catch((error) => callback(error));
|
||||
} else if (callback.length === 1) {
|
||||
promise
|
||||
.then((state) => callback(state))
|
||||
.catch((error) => callback({error: error}));
|
||||
}
|
||||
}
|
||||
return promise;
|
||||
static async query(...args) {
|
||||
return await Gamedig.getInstance().query(...args);
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Gamedig, "debug", { set: on => Gamedig.getInstance().setDebug(on) });
|
||||
|
||||
module.exports = Gamedig;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue