Implement client replying to deliver and center to submit_sm

This commit is contained in:
David Majdandžić
2023-03-25 16:16:14 +01:00
parent 14ed759c1a
commit 10da85dd90

47
main.js
View File

@@ -223,9 +223,16 @@ class ClientSession {
this.eventEmitter.emit(ClientSession.ANY_PDU_EVENT, payload); this.eventEmitter.emit(ClientSession.ANY_PDU_EVENT, payload);
} }
}); });
this.session.on('pdu', this.sessionPdu.bind(this));
this.connectingPromise.resolve(); this.connectingPromise.resolve();
} }
sessionPdu(pdu) {
if (pdu.command === 'deliver_sm') {
this.session.send(pdu.response());
}
}
bind() { bind() {
this.bindingPromise.promise = new Promise((resolve, reject) => { this.bindingPromise.promise = new Promise((resolve, reject) => {
if (this.status !== ClientSessionStatus.CONNECTED) { if (this.status !== ClientSessionStatus.CONNECTED) {
@@ -527,10 +534,13 @@ class CenterSession {
sessionPdu(session, pdu) { sessionPdu(session, pdu) {
// TODO: Implement ECHO and DR functionality // TODO: Implement ECHO and DR functionality
session.send(pdu.response()); if (pdu.command === 'submit_sm') {
session.send(pdu.response());
}
} }
notify(source, destination, message) { notify(source, destination, message) {
// TODO: Fix this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.canSend()) { if (!this.canSend()) {
this.logger.log1(`Cannot send message, no client connected on ${this.port} or busy`); this.logger.log1(`Cannot send message, no client connected on ${this.port} or busy`);
@@ -538,11 +548,11 @@ class CenterSession {
return; return;
} }
this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message}`); this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message}`);
this.getNextSession().submit_sm({ this.getNextSession().deliver_sm({
source_addr: source, source_addr: source,
destination_addr: destination, destination_addr: destination,
short_message: message short_message: message
}, pdu => { }, pdu => {
resolve(pdu); resolve(pdu);
}); });
}); });
@@ -1122,11 +1132,15 @@ centerSessionManager.startup();
// let session = clientSessionManager.createSession('smpp://localhost:7001', 'test', 'test'); // let session = clientSessionManager.createSession('smpp://localhost:7001', 'test', 'test');
// let server = centerSessionManager.createSession(7001, 'test', 'test'); // let server = centerSessionManager.createSession(7001, 'test', 'test');
let session = clientSessionManager.getSession(0);
let server = centerSessionManager.getSession(0);
// session.connect() // session.connect()
// .then(() => { // .then(() => {
// session.bind().catch(err => console.log(err)); // session.bind().then(() => {
// // server.notify('src', 'dst', 'msg');
// }).catch(err => console.log(err));
// }).catch(err => console.log(err)); // }).catch(err => console.log(err));
// // //
// setTimeout(() => session.setUsername("test123"), 2000); // setTimeout(() => session.setUsername("test123"), 2000);
// setTimeout(() => session.setPassword("test123"), 4000); // setTimeout(() => session.setPassword("test123"), 4000);
@@ -1134,6 +1148,13 @@ centerSessionManager.startup();
// console.log(pdu); // console.log(pdu);
// }); // });
session.on(ClientSession.ANY_PDU_EVENT, (pdu) => {
if (pdu.command.includes('enquire')) {
return;
}
console.log(pdu);
});
new WSServer(); new WSServer();
new HTTPServer(); new HTTPServer();
@@ -1143,8 +1164,8 @@ function cleanup() {
process.exit(0); process.exit(0);
} }
process.on('exit', cleanup); // process.on('exit', cleanup);
process.on('SIGINT', cleanup); // process.on('SIGINT', cleanup);
process.on('SIGUSR1', cleanup); // process.on('SIGUSR1', cleanup);
process.on('SIGUSR2', cleanup); // process.on('SIGUSR2', cleanup);
process.on('uncaughtException', cleanup); // process.on('uncaughtException', cleanup);