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;
|
_password: string;
|
||||||
_id: number;
|
_id: number;
|
||||||
_status: string = this.STATUS[0];
|
_status: string = this.STATUS[0];
|
||||||
_defaultSingleJob: Job;
|
|
||||||
_defaultMultipleJob: Job;
|
|
||||||
port: number;
|
port: number;
|
||||||
|
|
||||||
pduProcessors: PduProcessor[] = [];
|
pduProcessors: PduProcessor[] = [];
|
||||||
@@ -44,6 +42,32 @@ export class Center extends SmppSession {
|
|||||||
this.initialize();
|
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> {
|
sendMultiple(job: Job): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.validateSessions(reject);
|
this.validateSessions(reject);
|
||||||
@@ -106,13 +130,13 @@ export class Center extends SmppSession {
|
|||||||
|
|
||||||
serialize(): object {
|
serialize(): object {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this._id,
|
||||||
port: this.port,
|
port: this.port,
|
||||||
username: this.username,
|
username: this._username,
|
||||||
password: this.password,
|
password: this._password,
|
||||||
status: this.status,
|
status: this._status,
|
||||||
defaultSingleJob: this.defaultSingleJob.serialize(),
|
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||||
defaultMultipleJob: this.defaultMultipleJob.serialize(),
|
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||||
processors: this.pduProcessors.map(p => p.serialize()),
|
processors: this.pduProcessors.map(p => p.serialize()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -19,15 +19,11 @@ export class Client extends SmppSession {
|
|||||||
"BOUND",
|
"BOUND",
|
||||||
"BUSY",
|
"BUSY",
|
||||||
]
|
]
|
||||||
|
|
||||||
url: string;
|
url: string;
|
||||||
_username: string;
|
_username: string;
|
||||||
_password: string;
|
_password: string;
|
||||||
_id: number;
|
_id: number;
|
||||||
_status: string = this.STATUS[0];
|
_status: string = this.STATUS[0];
|
||||||
_defaultSingleJob: Job;
|
|
||||||
_defaultMultipleJob: Job;
|
|
||||||
|
|
||||||
pduProcessors: PduProcessor[] = [];
|
pduProcessors: PduProcessor[] = [];
|
||||||
readonly logger: Logger;
|
readonly logger: Logger;
|
||||||
private session?: any;
|
private session?: any;
|
||||||
@@ -48,6 +44,32 @@ export class Client extends SmppSession {
|
|||||||
this.logger = new Logger(`Client-${id}`);
|
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 {
|
doConnect(): PersistentPromise {
|
||||||
this.connectPromise = new PersistentPromise((resolve, reject) => {
|
this.connectPromise = new PersistentPromise((resolve, reject) => {
|
||||||
if (this.status !== this.STATUS[0]) {
|
if (this.status !== this.STATUS[0]) {
|
||||||
@@ -90,13 +112,13 @@ export class Client extends SmppSession {
|
|||||||
|
|
||||||
serialize(): object {
|
serialize(): object {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this._id,
|
||||||
url: this.url,
|
url: this.url,
|
||||||
username: this.username,
|
username: this._username,
|
||||||
password: this.password,
|
password: this._password,
|
||||||
status: this.status,
|
status: this._status,
|
||||||
defaultSingleJob: this.defaultSingleJob.serialize(),
|
defaultSingleJob: this._defaultSingleJob.serialize(),
|
||||||
defaultMultipleJob: this.defaultMultipleJob.serialize(),
|
defaultMultipleJob: this._defaultMultipleJob.serialize(),
|
||||||
processors: this.pduProcessors.map(p => p.serialize()),
|
processors: this.pduProcessors.map(p => p.serialize()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,32 @@
|
|||||||
export type PDU = {
|
export type PDU = {
|
||||||
command?: string;
|
command?: string;
|
||||||
|
command_id?: number;
|
||||||
|
command_length?: number;
|
||||||
command_status?: number;
|
command_status?: number;
|
||||||
system_id?: string;
|
data_coding?: number;
|
||||||
password?: string;
|
dest_addr_npi?: number;
|
||||||
source_addr?: string;
|
dest_addr_ton?: number;
|
||||||
destination_addr?: string;
|
destination_addr?: string;
|
||||||
short_message?: string;
|
esm_class?: number,
|
||||||
response?: (...args: any[]) => PDU;
|
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 = {
|
export type SerializedJob = {
|
||||||
pdu: PDU;
|
pdu: PDU;
|
||||||
perSecond?: number;
|
|
||||||
count?: number;
|
count?: number;
|
||||||
}
|
perSecond?: number;
|
||||||
|
};
|
@@ -46,18 +46,6 @@ export class Job {
|
|||||||
this.eventEmitter.emit(Job.STATE_CHANGED, {});
|
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 {
|
static createEmptySingle(): Job {
|
||||||
return new 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 {
|
serialize(): SerializedJob {
|
||||||
return {
|
return {
|
||||||
pdu: this.pdu,
|
pdu: this.pdu,
|
||||||
|
@@ -83,8 +83,8 @@ export abstract class SessionManager {
|
|||||||
}, err => {
|
}, err => {
|
||||||
});
|
});
|
||||||
this.verifyField(arg, reject);
|
this.verifyField(arg, reject);
|
||||||
this.verifyField(username, reject);
|
username = username || "";
|
||||||
this.verifyField(password, reject);
|
password = password || "";
|
||||||
|
|
||||||
let session = new this.ManagedSessionClass(this.sessionId++, arg, username, password);
|
let session = new this.ManagedSessionClass(this.sessionId++, arg, username, password);
|
||||||
this.addSession(session).then(() => {
|
this.addSession(session).then(() => {
|
||||||
|
@@ -20,7 +20,7 @@ export class WSServer {
|
|||||||
this.sessionManagers = sessionManagers;
|
this.sessionManagers = sessionManagers;
|
||||||
this.logger = new Logger("WSServer");
|
this.logger = new Logger("WSServer");
|
||||||
this.server.on('connection', this.eventOnConnection.bind(this));
|
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 {
|
private eventOnConnection(ws: WebSocket): void {
|
||||||
|
Reference in New Issue
Block a user