More refactoring

This commit is contained in:
David Majdandžić
2023-03-28 04:28:08 +02:00
parent 75392079f7
commit c917bf6cc8
7 changed files with 97 additions and 50 deletions

71
src/Job/Job.ts Normal file
View File

@@ -0,0 +1,71 @@
import EventEmitter from "events";
import {JobEvents} from "./JobEvents";
const smpp = require("smpp");
export class Job {
private eventEmitter: EventEmitter = new EventEmitter();
constructor(pdu: any, perSecond?: number, count?: number) {
this._pdu = pdu;
this._perSecond = perSecond;
this._count = count;
}
private _pdu: any;
get pdu(): any {
return this._pdu;
}
set pdu(value: any) {
this._pdu = value;
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
}
private _perSecond?: number;
get perSecond(): number {
return <number>this._perSecond;
}
set perSecond(value: number) {
this._perSecond = value;
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
}
private _count?: number;
get count(): number {
return <number>this._count;
}
set count(value: number) {
this._count = value;
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
}
static deserialize(serialized: any): Job {
if (!serialized._pdu) {
return Job.createEmptyMultiple();
}
let pdu: any = new smpp.PDU(serialized._pdu.command, serialized._pdu);
return new Job(pdu, serialized._perSecond, serialized._count);
}
static createEmptySingle(): Job {
return new Job({});
}
static createEmptyMultiple(): Job {
return new Job({}, 1, 1);
}
serialize(): string {
return JSON.stringify(this);
}
on(event: string, callback: (...args: any[]) => void): void {
this.eventEmitter.on(event, callback);
}
}

3
src/Job/JobEvents.ts Normal file
View File

@@ -0,0 +1,3 @@
export class JobEvents {
static readonly STATE_CHANGED: string = "STATE_CHANGED";
}