Code polish

This commit is contained in:
David Majdandžić
2023-03-31 20:24:59 +02:00
parent fb310fa53a
commit 5b26dd6a61
9 changed files with 26 additions and 20 deletions

View File

@@ -141,10 +141,6 @@ export class Center extends SmppSession {
};
}
getPort(): number {
return this.port;
}
private validateSessions(reject: (reason?: any) => void) {
if (this.sessions.length === 0) {
reject(`No clients connected`);

View File

@@ -18,5 +18,5 @@ export class CenterSessionManager extends SessionManager {
this.setup();
}
comparatorFn: (arg: any, session: SmppSession) => boolean = (arg: any, session: SmppSession) => (session as Center).getPort() === arg;
comparatorFn: (arg: any, session: SmppSession) => boolean = (arg: any, session: SmppSession) => (session as Center).port === arg;
}

View File

@@ -175,10 +175,6 @@ export class Client extends SmppSession {
});
}
getUrl(): string {
return this.url;
}
private connectSession(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.validateFields(reject);
@@ -198,11 +194,13 @@ export class Client extends SmppSession {
this.setStatus(2);
if (this.connectPromise) {
this.connectPromise.resolve();
} else {
this.logger.log1(`Client-${this.id} connected without connect promise`);
}
}
private eventSessionError(pdu: PDU): void {
this.logger.log1(`Client-${this.id} error on ${this.url}`);
private eventSessionError(pdu: any): void {
this.logger.log1(`Client-${this.id} error on ${this.url} - ${pdu.message}`);
this.setStatus(0);
this.rejectPromises();
}

View File

@@ -18,5 +18,5 @@ export default class ClientSessionManager extends SessionManager {
this.setup();
}
comparatorFn: (arg: any, session: SmppSession) => boolean = (arg: any, session: SmppSession) => (session as Client).getUrl() === arg;
comparatorFn: (arg: any, session: SmppSession) => boolean = (arg: any, session: SmppSession) => (session as Client).url === arg;
}

View File

@@ -55,7 +55,7 @@ export default class ClientRequestHandler extends RequestHandler {
doConnect(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Connecting client session with ID ${req.params.id}`)
this.logger.log1(`Connecting client session with ID ${req.params.id}`);
let client = session as Client;
client.doConnect()
.then(() => res.send(session.serialize()))

View File

@@ -43,7 +43,7 @@ export abstract class RequestHandler {
doSendSingleJob(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Sending pre-configured message on session with ID ${req.params.id}`)
this.logger.log1(`Sending pre-configured message on session with ID ${req.params.id}`);
session.sendSingleDefault()
.then(pdu => res.send(pdu),
err => res.status(400).send({
@@ -55,7 +55,7 @@ export abstract class RequestHandler {
doSend(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Sending message on session with ID ${req.params.id}`)
this.logger.log1(`Sending message on session with ID ${req.params.id}`);
let tempJob: Job = JSON.parse(JSON.stringify(session.defaultSingleJob));
tempJob.pdu.source_addr = req.body.source;
tempJob.pdu.destination_addr = req.body.destination;
@@ -73,14 +73,14 @@ export abstract class RequestHandler {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
let job: Job = session.defaultMultipleJob;
job.update(req);
this.logger.log1(`Updating default job on session with ID ${req.params.id}`)
this.logger.log1(`Updating default job on session with ID ${req.params.id}`);
res.send(session.serialize());
}, this.handleSessionNotFound.bind(this, req, res));
}
doSendManyJob(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Sending pre-configured messages on session with ID ${req.params.id}`)
this.logger.log1(`Sending pre-configured messages on session with ID ${req.params.id}`);
session.sendMultipleDefault()
.then(() => res.send({}),
err => res.status(400).send({
@@ -92,7 +92,7 @@ export abstract class RequestHandler {
doSendMany(req: any, res: any) {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Sending message on session with ID ${req.params.id}`)
this.logger.log1(`Sending message on session with ID ${req.params.id}`);
let tempJob: Job = JSON.parse(JSON.stringify(session.defaultMultipleJob));
tempJob.pdu.source_addr = req.body.source;
tempJob.pdu.destination_addr = req.body.destination;
@@ -112,6 +112,7 @@ export abstract class RequestHandler {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Cancelling send timer for session with ID ${req.params.id}`);
session.cancelSendInterval();
res.send({});
}, this.handleSessionNotFound.bind(this, req, res));
}
@@ -127,7 +128,9 @@ export abstract class RequestHandler {
doDelete(req: any, res: any) {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
this.logger.log1(`Deleting session with ID ${req.params.id}`);
this.sessionManager.removeSession(session);
res.send({});
}, this.handleSessionNotFound.bind(this, req, res));
}

View File

@@ -5,9 +5,9 @@ export default class PersistentPromise {
constructor(callback: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void) {
this.promise = new Promise((resolve, reject) => {
callback(resolve, reject);
this.promiseResolve = resolve;
this.promiseReject = reject;
callback(resolve, reject);
});
}

View File

@@ -31,6 +31,10 @@ export abstract class SmppSession {
abstract _username: string;
get username(): string {
return this._username;
}
set username(username: string) {
this._username = username;
this.eventEmitter.emit(this.EVENT.STATE_CHANGED, this.serialize());
@@ -38,6 +42,10 @@ export abstract class SmppSession {
abstract _password: string;
get password(): string {
return this._password;
}
set password(password: string) {
this._password = password;
this.eventEmitter.emit(this.EVENT.STATE_CHANGED, this.serialize());

View File

@@ -6,7 +6,8 @@
"rootDir": "./src",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
"esModuleInterop": true,
"noImplicitAny": true,
},
"exclude": [
"./node_modules"