mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-17 03:20:39 +00:00
Cleanup in cqi over socketio
This commit is contained in:
@ -1,18 +1,16 @@
|
||||
cqi.api.APIClient = class APIClient {
|
||||
/**
|
||||
* @param {string} host
|
||||
* @param {string} corpusId
|
||||
* @param {number} [timeout=60] timeout
|
||||
* @param {string} [version=0.1] version
|
||||
*/
|
||||
constructor(host, corpus_id, timeout = 60, version = '0.1') {
|
||||
constructor(host, timeout = 60, version = '0.1') {
|
||||
this.host = host;
|
||||
this.timeout = timeout * 1000; // convert seconds to milliseconds
|
||||
this.version = version;
|
||||
this.socket = io(
|
||||
this.host,
|
||||
{
|
||||
auth: {corpus_id: corpus_id},
|
||||
transports: ['websocket'],
|
||||
upgrade: false
|
||||
}
|
||||
@ -24,22 +22,16 @@ cqi.api.APIClient = class APIClient {
|
||||
* @param {object} [fn_args={}]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
#request(fn_name, fn_args = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// this.socket.timeout(this.timeout).emit('cqi', {fn_name: fn_name, fn_args: fn_args}, (timeoutError, response) => {
|
||||
// if (timeoutError) {
|
||||
// reject(timeoutError);
|
||||
// }
|
||||
this.socket.emit('cqi', fn_name, fn_args, (response) => {
|
||||
if (response.code === 200) {
|
||||
resolve(response.payload);
|
||||
} else if (response.code === 500) {
|
||||
reject(new Error(`[${response.code}] ${response.msg}`));
|
||||
} else if (response.code === 502) {
|
||||
reject(new cqi.errors.lookup[response.payload.code]());
|
||||
}
|
||||
});
|
||||
});
|
||||
async #request(fn_name, fn_args = {}) {
|
||||
// TODO: implement timeout
|
||||
let response = await this.socket.emitWithAck('exec', fn_name, fn_args);
|
||||
if (response.code === 200) {
|
||||
return response.payload;
|
||||
} else if (response.code === 500) {
|
||||
throw new Error(`[${response.code}] ${response.msg}`);
|
||||
} else if (response.code === 502) {
|
||||
throw new cqi.errors.lookup[response.payload.code]();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user