diff --git a/src/Center/Center.ts b/src/Center/Center.ts index 1a0ee6c..62a0bac 100644 --- a/src/Center/Center.ts +++ b/src/Center/Center.ts @@ -9,7 +9,7 @@ const NanoTimer = require('nanotimer'); const smpp = require("smpp"); export class Center extends SmppSession { - readonly STATUS: string[] = [ + readonly STATUSES: string[] = [ "WAITING CONNECTION", "CONNECTING", "CONNECTED", @@ -18,7 +18,7 @@ export class Center extends SmppSession { _username: string; _password: string; _id: number; - _status: string = this.STATUS[0]; + _status: string = this.STATUSES[0]; port: number; pduProcessors: PduProcessor[] = []; @@ -93,7 +93,6 @@ export class Center extends SmppSession { this.sendTimer.setInterval(() => { if (count > 0 && counter >= count) { this.cancelSendInterval(); - this.setStatus(2); } else { this.sendPdu(job.pdu, true); counter++; diff --git a/src/Client/Client.ts b/src/Client/Client.ts index 45e1cbe..4a9c4e4 100644 --- a/src/Client/Client.ts +++ b/src/Client/Client.ts @@ -11,7 +11,7 @@ const smpp = require("smpp"); const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000; export class Client extends SmppSession { - readonly STATUS: string[] = [ + readonly STATUSES: string[] = [ "NOT CONNECTED", "CONNECTING", "CONNECTED", @@ -23,7 +23,7 @@ export class Client extends SmppSession { _username: string; _password: string; _id: number; - _status: string = this.STATUS[0]; + _status: string = this.STATUSES[0]; pduProcessors: PduProcessor[] = []; readonly logger: Logger; private session?: any; @@ -72,7 +72,7 @@ export class Client extends SmppSession { doConnect(): PersistentPromise { 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`; this.logger.log1(errorString); reject(errorString); @@ -150,8 +150,8 @@ export class Client extends SmppSession { this.setStatus(4); - let counter = 0; - let previousUpdateCounter = 0; + let counter: number = 0; + let previousUpdateCounter: number = 0; this.counterUpdateTimer.setInterval(() => { if (previousUpdateCounter !== counter) { @@ -160,8 +160,9 @@ export class Client extends SmppSession { } }, '', `${this.MESSAGE_SEND_UPDATE_DELAY / 1000} s`); - let count = job.count || 1; - let interval = 1 / (job.perSecond || 1); + let count: number = job.count || 1; + let interval: number = 1 / (job.perSecond || 1); + this.setStatus(5); this.sendTimer.setInterval(() => { if (count > 0 && counter >= count) { this.cancelSendInterval(); @@ -266,7 +267,7 @@ export class Client extends SmppSession { } 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`; this.logger.log1(errorMessage); reject(errorMessage); diff --git a/src/SmppSession.ts b/src/SmppSession.ts index e9338c6..2a4e4eb 100644 --- a/src/SmppSession.ts +++ b/src/SmppSession.ts @@ -13,7 +13,7 @@ export abstract class SmppSession { ANY_PDU: "ANY_PDU", MESSAGE_SEND_COUNTER_UPDATE_EVENT: "MESSAGE_SEND_COUNTER_UPDATE_EVENT", }; - abstract STATUS: string[]; + abstract STATUSES: string[]; abstract pduProcessors: PduProcessor[]; readonly UPDATE_WS: string = "UPDATE_WS"; readonly eventEmitter: EventEmitter = new EventEmitter(); @@ -93,7 +93,7 @@ export abstract class SmppSession { } setStatus(statusIndex: number) { - this._status = this.STATUS[statusIndex]; + this._status = this.STATUSES[statusIndex]; this.eventEmitter.emit(this.EVENT.STATUS_CHANGED, this.status); } @@ -116,6 +116,7 @@ export abstract class SmppSession { cancelSendInterval(): void { this.sendTimer.clearInterval(); this.counterUpdateTimer.clearInterval(); + this.setStatus(this.STATUSES.length - 2); } abstract close(): Promise;