From 17a1c10c0524b8d26f347bbb616732ee2b764bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Thu, 30 Mar 2023 18:24:57 +0200 Subject: [PATCH] Fix issue with jobs not being assigned a command --- src/Center/Center.ts | 40 ++++++++++++++++++++++++++++++++-------- src/Client/Client.ts | 42 ++++++++++++++++++++++++++++++++---------- src/CommonObjects.ts | 33 +++++++++++++++++++++++++-------- src/Job/Job.ts | 24 ++++++++++++------------ src/SessionManager.ts | 4 ++-- src/WS/WSServer.ts | 2 +- 6 files changed, 104 insertions(+), 41 deletions(-) diff --git a/src/Center/Center.ts b/src/Center/Center.ts index bf06139..39dd8c7 100644 --- a/src/Center/Center.ts +++ b/src/Center/Center.ts @@ -18,8 +18,6 @@ export class Center extends SmppSession { _password: string; _id: number; _status: string = this.STATUS[0]; - _defaultSingleJob: Job; - _defaultMultipleJob: Job; port: number; pduProcessors: PduProcessor[] = []; @@ -44,6 +42,32 @@ export class Center extends SmppSession { this.initialize(); } + _defaultSingleJob: Job; + + get defaultSingleJob(): Job { + return this._defaultSingleJob; + } + + set defaultSingleJob(job: Job) { + if (job.pdu && !job.pdu.command) { + job.pdu.command = 'deliver_sm'; + } + super.defaultSingleJob = job; + } + + _defaultMultipleJob: Job; + + get defaultMultipleJob(): Job { + return this._defaultMultipleJob; + } + + set defaultMultipleJob(job: Job) { + if (job.pdu && !job.pdu.command) { + job.pdu.command = 'deliver_sm'; + } + super.defaultMultipleJob = job; + } + sendMultiple(job: Job): Promise { return new Promise((resolve, reject) => { this.validateSessions(reject); @@ -106,13 +130,13 @@ export class Center extends SmppSession { serialize(): object { return { - id: this.id, + id: this._id, port: this.port, - username: this.username, - password: this.password, - status: this.status, - defaultSingleJob: this.defaultSingleJob.serialize(), - defaultMultipleJob: this.defaultMultipleJob.serialize(), + username: this._username, + password: this._password, + status: this._status, + defaultSingleJob: this._defaultSingleJob.serialize(), + defaultMultipleJob: this._defaultMultipleJob.serialize(), processors: this.pduProcessors.map(p => p.serialize()), }; } diff --git a/src/Client/Client.ts b/src/Client/Client.ts index c2f6bed..d0f3ae2 100644 --- a/src/Client/Client.ts +++ b/src/Client/Client.ts @@ -19,15 +19,11 @@ export class Client extends SmppSession { "BOUND", "BUSY", ] - url: string; _username: string; _password: string; _id: number; _status: string = this.STATUS[0]; - _defaultSingleJob: Job; - _defaultMultipleJob: Job; - pduProcessors: PduProcessor[] = []; readonly logger: Logger; private session?: any; @@ -48,6 +44,32 @@ export class Client extends SmppSession { this.logger = new Logger(`Client-${id}`); } + _defaultSingleJob: Job; + + get defaultSingleJob(): Job { + return this._defaultSingleJob; + } + + set defaultSingleJob(job: Job) { + if (job.pdu && !job.pdu.command) { + job.pdu.command = 'submit_sm'; + } + super.defaultSingleJob = job; + } + + _defaultMultipleJob: Job; + + get defaultMultipleJob(): Job { + return this._defaultMultipleJob; + } + + set defaultMultipleJob(job: Job) { + if (job.pdu && !job.pdu.command) { + job.pdu.command = 'submit_sm'; + } + super.defaultMultipleJob = job; + } + doConnect(): PersistentPromise { this.connectPromise = new PersistentPromise((resolve, reject) => { if (this.status !== this.STATUS[0]) { @@ -90,13 +112,13 @@ export class Client extends SmppSession { serialize(): object { return { - id: this.id, + id: this._id, url: this.url, - username: this.username, - password: this.password, - status: this.status, - defaultSingleJob: this.defaultSingleJob.serialize(), - defaultMultipleJob: this.defaultMultipleJob.serialize(), + username: this._username, + password: this._password, + status: this._status, + defaultSingleJob: this._defaultSingleJob.serialize(), + defaultMultipleJob: this._defaultMultipleJob.serialize(), processors: this.pduProcessors.map(p => p.serialize()), }; } diff --git a/src/CommonObjects.ts b/src/CommonObjects.ts index 74cad1a..e4d5010 100644 --- a/src/CommonObjects.ts +++ b/src/CommonObjects.ts @@ -1,15 +1,32 @@ export type PDU = { command?: string; + command_id?: number; + command_length?: number; command_status?: number; - system_id?: string; - password?: string; - source_addr?: string; + data_coding?: number; + dest_addr_npi?: number; + dest_addr_ton?: number; destination_addr?: string; - short_message?: string; - response?: (...args: any[]) => PDU; -} + esm_class?: number, + password?: string, + priority_flag?: number, + protocol_id?: number, + registered_delivery?: number, + replace_if_present_flag?: number, + response?: (...args: any[]) => PDU, + schedule_delivery_time?: string, + sequence_number?: number, + service_type?: string, + short_message?: string, + sm_default_msg_id?: number, + source_addr?: string, + source_addr_npi?: number, + source_addr_ton?: number, + system_id?: string, + validity_period?: string +}; export type SerializedJob = { pdu: PDU; - perSecond?: number; count?: number; -} \ No newline at end of file + perSecond?: number; +}; \ No newline at end of file diff --git a/src/Job/Job.ts b/src/Job/Job.ts index 8f545b5..b6acd26 100644 --- a/src/Job/Job.ts +++ b/src/Job/Job.ts @@ -46,18 +46,6 @@ export class Job { this.eventEmitter.emit(Job.STATE_CHANGED, {}); } - static deserialize(serialized: SerializedJob): Job { - if (!serialized.pdu || !serialized.pdu.command) { - if (!serialized.perSecond && !serialized.count) { - return Job.createEmptySingle(); - } else { - return Job.createEmptyMultiple(); - } - } - let pdu: PDU = new smpp.PDU(serialized.pdu.command, serialized.pdu); - return new Job(pdu, serialized.perSecond, serialized.count); - } - static createEmptySingle(): Job { return new Job({}); } @@ -84,6 +72,18 @@ export class Job { } } + static deserialize(serialized: SerializedJob): Job { + if (!serialized.pdu || !serialized.pdu.command) { + if (!serialized.perSecond && !serialized.count) { + return Job.createEmptySingle(); + } else { + return Job.createEmptyMultiple(); + } + } + let pdu: PDU = new smpp.PDU(serialized.pdu.command, serialized.pdu); + return new Job(pdu, serialized.perSecond, serialized.count); + } + serialize(): SerializedJob { return { pdu: this.pdu, diff --git a/src/SessionManager.ts b/src/SessionManager.ts index 3294d3c..1455e1a 100644 --- a/src/SessionManager.ts +++ b/src/SessionManager.ts @@ -83,8 +83,8 @@ export abstract class SessionManager { }, err => { }); this.verifyField(arg, reject); - this.verifyField(username, reject); - this.verifyField(password, reject); + username = username || ""; + password = password || ""; let session = new this.ManagedSessionClass(this.sessionId++, arg, username, password); this.addSession(session).then(() => { diff --git a/src/WS/WSServer.ts b/src/WS/WSServer.ts index 0a9640f..cab364c 100644 --- a/src/WS/WSServer.ts +++ b/src/WS/WSServer.ts @@ -20,7 +20,7 @@ export class WSServer { this.sessionManagers = sessionManagers; this.logger = new Logger("WSServer"); this.server.on('connection', this.eventOnConnection.bind(this)); - this.logger.log1(`WSServer listening atws://localhost:${WS_SERVER_PORT}`); + this.logger.log1(`WSServer listening at ws://localhost:${WS_SERVER_PORT}`); } private eventOnConnection(ws: WebSocket): void {