diff --git a/src/Center/Center.ts b/src/Center/Center.ts index f7e101e..0676ba0 100644 --- a/src/Center/Center.ts +++ b/src/Center/Center.ts @@ -2,7 +2,6 @@ import {Job} from "../Job/Job"; import Logger from "../Logger"; import {PduProcessor} from "../PDUProcessor/PduProcessor"; import {SmppSession} from "../SmppSession"; -import CenterStatus from "./CenterStatus"; const NanoTimer = require('nanotimer'); const smpp = require("smpp"); @@ -180,11 +179,11 @@ export class Center extends SmppSession { private updateStatus(): void { if (this.sessions.length > 0) { - this.status = CenterStatus.CONNECTED; + this.setStatus(2); } else if (this.pendingSessions.length > 0) { - this.status = CenterStatus.CONNECTING; + this.setStatus(1); } else { - this.status = CenterStatus.WAITING_CONNECTION; + this.setStatus(0); } } } \ No newline at end of file diff --git a/src/Center/CenterStatus.ts b/src/Center/CenterStatus.ts deleted file mode 100644 index dd81c01..0000000 --- a/src/Center/CenterStatus.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class CenterStatus { - static readonly WAITING_CONNECTION: string = "WAITING CONNECTION"; - static readonly CONNECTING: string = "CONNECTING"; - static readonly CONNECTED: string = "CONNECTED"; -} \ No newline at end of file diff --git a/src/Client/Client.ts b/src/Client/Client.ts index 0e4395c..be9b2b9 100644 --- a/src/Client/Client.ts +++ b/src/Client/Client.ts @@ -8,7 +8,6 @@ const NanoTimer = require('nanotimer'); const smpp = require("smpp"); const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000; -const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE_DELAY) || 500; export class Client extends SmppSession { readonly STATUS: string[] = [ @@ -103,12 +102,8 @@ export class Client extends SmppSession { } close(): Promise { - return new Promise((resolve, reject) => { - this.logger.log1(`Client-${this.getId()} closing connection`); - this.session.close(); - this.setStatus(0); - resolve(); - }); + this.logger.log1(`Client-${this.getId()} closing connection`); + return Promise.resolve(this.session.close()); } sendPdu(pdu: object, force?: boolean): Promise { @@ -141,7 +136,7 @@ export class Client extends SmppSession { this.eventEmitter.emit(this.EVENT.MESSAGE_SEND_COUNTER_UPDATE_EVENT, counter); previousUpdateCounter = counter; } - }, '', `${MESSAGE_SEND_UPDATE_DELAY / 1000} s`); + }, '', `${this.MESSAGE_SEND_UPDATE_DELAY / 1000} s`); let count = job.count || 1; let interval = 1 / (job.perSecond || 1); diff --git a/src/Client/ClientStatus.ts b/src/Client/ClientStatus.ts deleted file mode 100644 index 00a0f7a..0000000 --- a/src/Client/ClientStatus.ts +++ /dev/null @@ -1,2 +0,0 @@ -export default class ClientStatus { -} \ No newline at end of file diff --git a/src/PDUProcessor/PduDebugProcessor.ts b/src/PDUProcessor/PduDebugProcessor.ts new file mode 100644 index 0000000..8e4ecd5 --- /dev/null +++ b/src/PDUProcessor/PduDebugProcessor.ts @@ -0,0 +1,15 @@ +import {PduProcessor} from "./PduProcessor"; + +export class PduDebugProcessor implements PduProcessor { + processPdu(session: any, pdu: any, ...args: any[]): Promise { + return new Promise((resolve, reject) => { + session.send(pdu.response(), (replyPdu: any) => { + resolve(replyPdu); + }); + }) + } + + serialize(): object { + return {}; + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index fe49f4f..fd5af0e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ import {Center} from "./Center/Center"; import {Client} from "./Client/Client"; import ClientSessionManager from "./Client/ClientSessionManager"; -import {Job} from "./Job/Job"; import Logger from "./Logger"; +import {PduDebugProcessor} from "./PDUProcessor/PduDebugProcessor"; const smpp = require("smpp"); const fs = require("fs"); @@ -18,7 +18,6 @@ const {PDU} = require("smpp"); const app = express(); const SERVER_PORT: number = Number(process.env.SERVER_PORT) || 8190; -const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE_DELAY) || 500; // TODO: Add support for encodings // TODO: Implement some sort of metrics on frontend by counting the pdus @@ -52,18 +51,20 @@ async function main() { // }); let center: Center = new Center(0, 7000, "test", "test"); - setTimeout(() => { - center.sendMultiple(new Job(new PDU("deliver_sm", { - source_addr: "1234567890", - destination_addr: "1234567890", - short_message: "Hello World" - }), 10, 100)); - // center.close(); - }, 5000); - - client.connectAndBind().then(() => { - console.log("POGGIES"); - }); + // setInterval(() => { + // client.connectAndBind().then(() => { + // console.log("POGGIES"); + // client.close(); + // }); + // }, 1000); + // setTimeout(() => { + // center.sendMultiple(new Job(new PDU("deliver_sm", { + // source_addr: "1234567890", + // destination_addr: "1234567890", + // short_message: "Hello World" + // }), 10, 100)); + // // center.close(); + // }, 5000); } main();