diff --git a/src/Center/Center.ts b/src/Center/Center.ts index bcb30e1..1b2ff11 100644 --- a/src/Center/Center.ts +++ b/src/Center/Center.ts @@ -111,8 +111,8 @@ export class Center extends SmppSession { username: this.username, password: this.password, status: this.status, - defaultSingleJob: this.defaultSingleJob, - defaultMultipleJob: this.defaultMultipleJob, + 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 13d14a4..14b0fd7 100644 --- a/src/Client/Client.ts +++ b/src/Client/Client.ts @@ -43,8 +43,8 @@ export class Client extends SmppSession { this.password = password; this.url = url; - this.setDefaultSingleJob(Job.createEmptySingle()); - this.setDefaultMultipleJob(Job.createEmptyMultiple()); + this.defaultSingleJob = Job.createEmptySingle(); + this.defaultMultipleJob = Job.createEmptyMultiple(); this.logger = new Logger(`Client-${id}`); } @@ -96,8 +96,8 @@ export class Client extends SmppSession { username: this.username, password: this.password, status: this.status, - defaultSingleJob: this.defaultSingleJob, - defaultMultipleJob: this.defaultMultipleJob, + defaultSingleJob: this.defaultSingleJob.serialize(), + defaultMultipleJob: this.defaultMultipleJob.serialize(), processors: this.pduProcessors.map(p => p.serialize()), }; } diff --git a/src/Job/Job.ts b/src/Job/Job.ts index 89efec8..0f42bc6 100644 --- a/src/Job/Job.ts +++ b/src/Job/Job.ts @@ -46,11 +46,11 @@ export class Job { } static deserialize(serialized: any): Job { - if (!serialized._pdu) { + if (!serialized.pdu || !serialized.pdu.command) { return Job.createEmptyMultiple(); } - let pdu: any = new smpp.PDU(serialized._pdu.command, serialized._pdu); - return new Job(pdu, serialized._perSecond, serialized._count); + let pdu: any = new smpp.PDU(serialized.pdu.command, serialized.pdu); + return new Job(pdu, serialized.perSecond, serialized.count); } static createEmptySingle(): Job { @@ -63,7 +63,7 @@ export class Job { serialize(): object { return { - pdu: JSON.stringify(this.pdu), + pdu: this.pdu, perSecond: this.perSecond, count: this.count }; diff --git a/src/SessionManager.ts b/src/SessionManager.ts index 629dca6..845a29f 100644 --- a/src/SessionManager.ts +++ b/src/SessionManager.ts @@ -57,13 +57,6 @@ export abstract class SessionManager { }); } - serialize(): object { - this.logger.log1(`Serializing ${this.sessions.length} clients`); - return this.sessions.map((session: SmppSession) => { - return session.serialize(); - }); - } - createSession(arg: any, username: string, password: string): Promise { return new Promise((resolve, reject) => { this.logger.log1(`Creating session of type ${this.ManagedSessionClass.name} with arg ${arg}`); @@ -113,6 +106,13 @@ export abstract class SessionManager { fs.writeFileSync(this.StorageFile, JSON.stringify(this.serialize(), null, 4)); } + serialize(): object { + this.logger.log1(`Serializing ${this.sessions.length} clients`); + return this.sessions.map((session: SmppSession) => { + return session.serialize(); + }); + } + getExisting(arg: any): Promise { return new Promise((resolve, reject) => { this.logger.log1(`Looking for session with arg ${arg}...`);