Clean up code
This commit is contained in:
@@ -69,6 +69,21 @@ export default class Center extends SmppSession {
|
||||
super.defaultMultipleJob = job;
|
||||
}
|
||||
|
||||
sendPdu(pdu: PDU, force?: boolean): Promise<object> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!force) {
|
||||
this.validateSessions(reject);
|
||||
}
|
||||
this.logger.log5(`Center-${this.id} sending PDU: ${JSON.stringify(pdu)}`);
|
||||
let pduCopy = new smpp.PDU(pdu.command, {...pdu});
|
||||
let session = this.getNextSession();
|
||||
this.processors.Preprocessor.forEach((processor: PduProcessor) => processor.processPdu(session, pduCopy));
|
||||
session.send(pduCopy, (replyPdu: any) => {
|
||||
resolve(replyPdu);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
sendMultiple(job: Job): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.validateSessions(reject);
|
||||
@@ -102,18 +117,6 @@ export default class Center extends SmppSession {
|
||||
});
|
||||
}
|
||||
|
||||
sendPdu(pdu: object, force?: boolean): Promise<object> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!force) {
|
||||
this.validateSessions(reject);
|
||||
}
|
||||
this.logger.log5(`Center-${this.id} sending PDU: ${JSON.stringify(pdu)}`);
|
||||
this.getNextSession().send(pdu, (replyPdu: any) => {
|
||||
resolve(replyPdu);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
initialize(): void {
|
||||
this.server = smpp.createServer({}, this.eventSessionConnected.bind(this));
|
||||
this.server.listen(this.port);
|
||||
@@ -140,8 +143,10 @@ export default class Center extends SmppSession {
|
||||
status: this._status,
|
||||
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||
processors: this.pduProcessors.map(p => p.serialize()),
|
||||
availableProcessors: ProcessorManager.getProcessorsForType(this.constructor.name)
|
||||
preprocessors: this.processors.Preprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
postprocessors: this.processors.Postprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
availablePreprocessors: ProcessorManager.getPreprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
availablePostprocessors: ProcessorManager.getPostprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -160,6 +165,7 @@ export default class Center extends SmppSession {
|
||||
return session;
|
||||
}
|
||||
|
||||
// TODO: Move this to smppSession and call postProcessors
|
||||
private eventBindTransceiver(session: any, pdu: PDU) {
|
||||
this.logger.log1(`Center-${this.id} got a bind_transciever with system_id ${pdu.system_id} and password ${pdu.password}`);
|
||||
session.pause();
|
||||
@@ -218,7 +224,7 @@ export default class Center extends SmppSession {
|
||||
}
|
||||
}
|
||||
|
||||
// No reaason for this to be a promise
|
||||
// TODO: Move this to smppSession and call postProcessors
|
||||
eventAnyPdu(session: any, pdu: any): Promise<any> {
|
||||
this.eventEmitter.emit(this.EVENT.ANY_PDU, pdu);
|
||||
let successful: number = 0;
|
||||
|
@@ -112,6 +112,7 @@ export default class Client extends SmppSession {
|
||||
}
|
||||
|
||||
serialize(): object {
|
||||
// TODO: Generify this further by moving it to smpp session and creating a... "postSerialize" that is abstract
|
||||
return {
|
||||
id: this._id,
|
||||
url: this.url,
|
||||
@@ -120,8 +121,10 @@ export default class Client extends SmppSession {
|
||||
status: this._status,
|
||||
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||
processors: this.pduProcessors.map(p => p.serialize()),
|
||||
availableProcessors: ProcessorManager.getProcessorsForType(this.constructor.name)
|
||||
preprocessors: this.processors.Preprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
postprocessors: this.processors.Postprocessor.map((p: PduProcessor) => p.serialize()),
|
||||
availablePreprocessors: ProcessorManager.getPreprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
availablePostprocessors: ProcessorManager.getPostprocessorsForType(this.constructor.name).map((p: PduProcessor) => p.serialize()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -130,14 +133,15 @@ export default class Client extends SmppSession {
|
||||
return Promise.resolve(this.session.close());
|
||||
}
|
||||
|
||||
sendPdu(pdu: any, force?: boolean): Promise<object> {
|
||||
sendPdu(pdu: PDU, force?: boolean): Promise<object> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!force) {
|
||||
this.validateSession(reject);
|
||||
this.validateBound(reject);
|
||||
}
|
||||
let pduCopy = new smpp.PDU(pdu.command, {...pdu})
|
||||
this.pduProcessors.forEach((processor: PduProcessor) => processor.processPdu(this.session, pduCopy));
|
||||
// Is this expensive...?
|
||||
let pduCopy = new smpp.PDU(pdu.command, {...pdu});
|
||||
this.processors.Preprocessor.forEach((processor: PduProcessor) => processor.processPdu(this.session, pduCopy));
|
||||
this.logger.log5(`Client-${this.id} sending PDU: ${JSON.stringify(pduCopy)}`);
|
||||
this.session.send(pduCopy, (replyPdu: object) => resolve(replyPdu));
|
||||
});
|
||||
@@ -180,6 +184,12 @@ export default class Client extends SmppSession {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Move this to smppSession and call postProcessors
|
||||
eventAnyPdu(session: any, pdu: any): Promise<any> {
|
||||
this.eventEmitter.emit(this.EVENT.ANY_PDU, pdu);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
private connectSession(): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.validateFields(reject);
|
||||
@@ -277,9 +287,4 @@ export default class Client extends SmppSession {
|
||||
reject(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
eventAnyPdu(session: any, pdu: any): Promise<any> {
|
||||
this.eventEmitter.emit(this.EVENT.ANY_PDU, pdu);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
@@ -87,4 +87,12 @@ export default class ProcessorManager {
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
|
||||
static getPreprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.preprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
|
||||
static getPostprocessorsForType(type: string): PduProcessor[] {
|
||||
return this.postprocessors.filter((processor: PduProcessor) => processor.sessionType === type);
|
||||
}
|
||||
}
|
@@ -177,14 +177,6 @@ export default abstract class SmppSession {
|
||||
detachPostprocessor(processor: PduProcessor): void {
|
||||
this.detachProcessor(processor, this.processors.Postprocessor);
|
||||
}
|
||||
|
||||
serializePduProcessors(): object {
|
||||
let processors: PduProcessor[] = this.processors.Preprocessor.concat(this.processors.Postprocessor);
|
||||
return processors.map((processor: PduProcessor) => {
|
||||
return processor.serialize();
|
||||
});
|
||||
}
|
||||
|
||||
abstract eventAnyPdu(session: any, pdu: any): Promise<any>;
|
||||
|
||||
private detachProcessor(processor: PduProcessor, array: PduProcessor[]): void {
|
||||
|
Reference in New Issue
Block a user