Fix issue with stop send not updating status

This commit is contained in:
David Majdandžić
2023-03-31 22:14:10 +02:00
parent de5faa4ac9
commit a5ecf37752
3 changed files with 14 additions and 13 deletions

View File

@@ -9,7 +9,7 @@ const NanoTimer = require('nanotimer');
const smpp = require("smpp"); const smpp = require("smpp");
export class Center extends SmppSession { export class Center extends SmppSession {
readonly STATUS: string[] = [ readonly STATUSES: string[] = [
"WAITING CONNECTION", "WAITING CONNECTION",
"CONNECTING", "CONNECTING",
"CONNECTED", "CONNECTED",
@@ -18,7 +18,7 @@ export class Center extends SmppSession {
_username: string; _username: string;
_password: string; _password: string;
_id: number; _id: number;
_status: string = this.STATUS[0]; _status: string = this.STATUSES[0];
port: number; port: number;
pduProcessors: PduProcessor[] = []; pduProcessors: PduProcessor[] = [];
@@ -93,7 +93,6 @@ export class Center extends SmppSession {
this.sendTimer.setInterval(() => { this.sendTimer.setInterval(() => {
if (count > 0 && counter >= count) { if (count > 0 && counter >= count) {
this.cancelSendInterval(); this.cancelSendInterval();
this.setStatus(2);
} else { } else {
this.sendPdu(job.pdu, true); this.sendPdu(job.pdu, true);
counter++; counter++;

View File

@@ -11,7 +11,7 @@ const smpp = require("smpp");
const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000; const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000;
export class Client extends SmppSession { export class Client extends SmppSession {
readonly STATUS: string[] = [ readonly STATUSES: string[] = [
"NOT CONNECTED", "NOT CONNECTED",
"CONNECTING", "CONNECTING",
"CONNECTED", "CONNECTED",
@@ -23,7 +23,7 @@ export class Client extends SmppSession {
_username: string; _username: string;
_password: string; _password: string;
_id: number; _id: number;
_status: string = this.STATUS[0]; _status: string = this.STATUSES[0];
pduProcessors: PduProcessor[] = []; pduProcessors: PduProcessor[] = [];
readonly logger: Logger; readonly logger: Logger;
private session?: any; private session?: any;
@@ -72,7 +72,7 @@ export class Client extends SmppSession {
doConnect(): PersistentPromise { doConnect(): PersistentPromise {
this.connectPromise = new PersistentPromise((resolve, reject) => { this.connectPromise = new PersistentPromise((resolve, reject) => {
if (this.status !== this.STATUS[0]) { if (this.status !== this.STATUSES[0]) {
let errorString = `Client-${this.id} already connected`; let errorString = `Client-${this.id} already connected`;
this.logger.log1(errorString); this.logger.log1(errorString);
reject(errorString); reject(errorString);
@@ -150,8 +150,8 @@ export class Client extends SmppSession {
this.setStatus(4); this.setStatus(4);
let counter = 0; let counter: number = 0;
let previousUpdateCounter = 0; let previousUpdateCounter: number = 0;
this.counterUpdateTimer.setInterval(() => { this.counterUpdateTimer.setInterval(() => {
if (previousUpdateCounter !== counter) { if (previousUpdateCounter !== counter) {
@@ -160,8 +160,9 @@ export class Client extends SmppSession {
} }
}, '', `${this.MESSAGE_SEND_UPDATE_DELAY / 1000} s`); }, '', `${this.MESSAGE_SEND_UPDATE_DELAY / 1000} s`);
let count = job.count || 1; let count: number = job.count || 1;
let interval = 1 / (job.perSecond || 1); let interval: number = 1 / (job.perSecond || 1);
this.setStatus(5);
this.sendTimer.setInterval(() => { this.sendTimer.setInterval(() => {
if (count > 0 && counter >= count) { if (count > 0 && counter >= count) {
this.cancelSendInterval(); this.cancelSendInterval();
@@ -266,7 +267,7 @@ export class Client extends SmppSession {
} }
private validateBound(reject: (reason?: any) => void) { private validateBound(reject: (reason?: any) => void) {
if (this.status !== this.STATUS[4]) { if (this.status !== this.STATUSES[4]) {
let errorMessage = `Client-${this.id} is not bound`; let errorMessage = `Client-${this.id} is not bound`;
this.logger.log1(errorMessage); this.logger.log1(errorMessage);
reject(errorMessage); reject(errorMessage);

View File

@@ -13,7 +13,7 @@ export abstract class SmppSession {
ANY_PDU: "ANY_PDU", ANY_PDU: "ANY_PDU",
MESSAGE_SEND_COUNTER_UPDATE_EVENT: "MESSAGE_SEND_COUNTER_UPDATE_EVENT", MESSAGE_SEND_COUNTER_UPDATE_EVENT: "MESSAGE_SEND_COUNTER_UPDATE_EVENT",
}; };
abstract STATUS: string[]; abstract STATUSES: string[];
abstract pduProcessors: PduProcessor[]; abstract pduProcessors: PduProcessor[];
readonly UPDATE_WS: string = "UPDATE_WS"; readonly UPDATE_WS: string = "UPDATE_WS";
readonly eventEmitter: EventEmitter = new EventEmitter(); readonly eventEmitter: EventEmitter = new EventEmitter();
@@ -93,7 +93,7 @@ export abstract class SmppSession {
} }
setStatus(statusIndex: number) { setStatus(statusIndex: number) {
this._status = this.STATUS[statusIndex]; this._status = this.STATUSES[statusIndex];
this.eventEmitter.emit(this.EVENT.STATUS_CHANGED, this.status); this.eventEmitter.emit(this.EVENT.STATUS_CHANGED, this.status);
} }
@@ -116,6 +116,7 @@ export abstract class SmppSession {
cancelSendInterval(): void { cancelSendInterval(): void {
this.sendTimer.clearInterval(); this.sendTimer.clearInterval();
this.counterUpdateTimer.clearInterval(); this.counterUpdateTimer.clearInterval();
this.setStatus(this.STATUSES.length - 2);
} }
abstract close(): Promise<void>; abstract close(): Promise<void>;