Finally make the stupid pre/post processors work
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import {PDU} from "../CommonObjects";
|
||||
import Logger from "../Logger";
|
||||
import SmppSession from "../SmppSession";
|
||||
|
||||
export default abstract class PduProcessor {
|
||||
abstract readonly serverSessionType: string;
|
||||
readonly serverSessionType: string;
|
||||
readonly name: string = this.constructor.name;
|
||||
readonly logger: Logger = new Logger(`PduProcessor: ${this.name}`);
|
||||
|
||||
constructor(type: string) {
|
||||
this.serverSessionType = type;
|
||||
}
|
||||
|
||||
abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>;
|
||||
|
||||
serialize(): object {
|
||||
|
@@ -1,9 +1,14 @@
|
||||
import Center from "../../../Center/Center";
|
||||
import Client from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export default class DebugPduProcessor extends Postprocessor {
|
||||
serverSessionType: string = Center.name;
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
console.log(this.serverSessionType);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
|
@@ -1,11 +1,15 @@
|
||||
import Center from "../../../Center/Center";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
export default class EchoPduProcessor extends Postprocessor {
|
||||
serverSessionType: string = Center.name;
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
console.log(this.serverSessionType);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
|
@@ -1,9 +1,13 @@
|
||||
import Client from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export default class DeliverSmReplyProcessor extends Postprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
console.log(this.serverSessionType);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
|
@@ -1,10 +1,14 @@
|
||||
import Client from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
private iterator = 0;
|
||||
private iterator: number = 0;
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
console.log(this.serverSessionType);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
|
@@ -1,10 +1,14 @@
|
||||
import Client from "../../../Client/Client";
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class SourceEnumeratorProcessor extends Preprocessor {
|
||||
serverSessionType: string = Client.name;
|
||||
private iterator = 0;
|
||||
private iterator: number = 0;
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
console.log(this.serverSessionType);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import Center from "../Center/Center";
|
||||
import Client from "../Client/Client";
|
||||
import Logger from "../Logger";
|
||||
import SmppSession from "../SmppSession";
|
||||
import PduProcessor from "./PduProcessor";
|
||||
@@ -8,18 +10,22 @@ import DestinationEnumeratorProcessor from "./Preprocessor/Client/DestinationEnu
|
||||
import SourceEnumeratorProcessor from "./Preprocessor/Client/SourceEnumeratorProcessor";
|
||||
|
||||
export default class ProcessorManager {
|
||||
static readonly preprocessors: PduProcessor[] = [
|
||||
new DestinationEnumeratorProcessor(),
|
||||
new SourceEnumeratorProcessor()
|
||||
];
|
||||
static readonly postprocessors: PduProcessor[] = [
|
||||
new DebugPduProcessor(),
|
||||
new EchoPduProcessor(),
|
||||
new DeliverSmReplyProcessor(),
|
||||
];
|
||||
static preprocessors: PduProcessor[];
|
||||
static postprocessors: PduProcessor[];
|
||||
private static readonly logger: Logger = new Logger(this.name);
|
||||
|
||||
constructor() {
|
||||
// This is an IDIOTIC solution, but it works
|
||||
// Try running eb22a43 to find out what's wrong with the previous approach
|
||||
ProcessorManager.preprocessors = [
|
||||
new DestinationEnumeratorProcessor(Client.name),
|
||||
new SourceEnumeratorProcessor(Client.name)
|
||||
];
|
||||
ProcessorManager.postprocessors = [
|
||||
new DebugPduProcessor(Center.name),
|
||||
new EchoPduProcessor(Center.name),
|
||||
new DeliverSmReplyProcessor(Center.name),
|
||||
];
|
||||
}
|
||||
|
||||
static get processors(): PduProcessor[] {
|
||||
|
@@ -6,7 +6,7 @@ const WebSocket = require("ws");
|
||||
|
||||
const WS_SERVER_PORT: number = Number(process.env.WS_SERVER_PORT) || 8191;
|
||||
|
||||
export class WSServer {
|
||||
export default class WSServer {
|
||||
private readonly clients: ClientSet[];
|
||||
private readonly unknownClients: any[];
|
||||
private readonly server: any;
|
||||
|
@@ -3,17 +3,20 @@ import CenterSessionManager from "./Center/CenterSessionManager";
|
||||
import Client from "./Client/Client";
|
||||
import ClientSessionManager from "./Client/ClientSessionManager";
|
||||
import Logger from "./Logger";
|
||||
import ProcessorManager from "./PDUProcessor/ProcessorManager";
|
||||
import WSServer from "./WS/WSServer";
|
||||
|
||||
const {PDU} = require("smpp");
|
||||
|
||||
let logger = new Logger("main");
|
||||
|
||||
new ProcessorManager();
|
||||
let clientManager: ClientSessionManager = new ClientSessionManager();
|
||||
let centerManager: CenterSessionManager = new CenterSessionManager();
|
||||
// TODO: Add support for encodings
|
||||
// TODO: Fix reading and writing processors
|
||||
// TODO: Try creating multiple entries with the same arg
|
||||
// let wss: WSServer = new WSServer([clientManager, centerManager]);
|
||||
let wss: WSServer = new WSServer([clientManager, centerManager]);
|
||||
// let httpServer: HttpServer = new HttpServer(clientManager, centerManager);
|
||||
|
||||
function cleanup(): void {
|
||||
@@ -38,6 +41,10 @@ async function main() {
|
||||
}
|
||||
|
||||
// main();
|
||||
console.log(ProcessorManager);
|
||||
// console.log(ProcessorManager.getProcessorsForType(Center.name));
|
||||
// console.log(ProcessorManager.processors);
|
||||
console.log("OK");
|
||||
|
||||
// process.on('exit', cleanup);
|
||||
// process.on('SIGINT', cleanup);
|
||||
|
Reference in New Issue
Block a user