Fix issue with jobs not being assigned a command
This commit is contained in:
@@ -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<void> {
|
||||
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()),
|
||||
};
|
||||
}
|
||||
|
@@ -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()),
|
||||
};
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
perSecond?: number;
|
||||
};
|
@@ -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,
|
||||
|
@@ -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(() => {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user