From 10da85dd90130f2e0f4a5b8312d3545dd3e97d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Sat, 25 Mar 2023 16:16:14 +0100 Subject: [PATCH] Implement client replying to deliver and center to submit_sm --- main.js | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index c44cda8..8dff59b 100644 --- a/main.js +++ b/main.js @@ -223,9 +223,16 @@ class ClientSession { this.eventEmitter.emit(ClientSession.ANY_PDU_EVENT, payload); } }); + this.session.on('pdu', this.sessionPdu.bind(this)); this.connectingPromise.resolve(); } + sessionPdu(pdu) { + if (pdu.command === 'deliver_sm') { + this.session.send(pdu.response()); + } + } + bind() { this.bindingPromise.promise = new Promise((resolve, reject) => { if (this.status !== ClientSessionStatus.CONNECTED) { @@ -527,10 +534,13 @@ class CenterSession { sessionPdu(session, pdu) { // TODO: Implement ECHO and DR functionality - session.send(pdu.response()); + if (pdu.command === 'submit_sm') { + session.send(pdu.response()); + } } notify(source, destination, message) { + // TODO: Fix this return new Promise((resolve, reject) => { if (!this.canSend()) { this.logger.log1(`Cannot send message, no client connected on ${this.port} or busy`); @@ -538,11 +548,11 @@ class CenterSession { return; } this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message}`); - this.getNextSession().submit_sm({ - source_addr: source, - destination_addr: destination, - short_message: message - }, pdu => { + this.getNextSession().deliver_sm({ + source_addr: source, + destination_addr: destination, + short_message: message + }, pdu => { resolve(pdu); }); }); @@ -1122,11 +1132,15 @@ centerSessionManager.startup(); // let session = clientSessionManager.createSession('smpp://localhost:7001', 'test', 'test'); // let server = centerSessionManager.createSession(7001, 'test', 'test'); +let session = clientSessionManager.getSession(0); +let server = centerSessionManager.getSession(0); // session.connect() // .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)); -// // +// // setTimeout(() => session.setUsername("test123"), 2000); // setTimeout(() => session.setPassword("test123"), 4000); @@ -1134,6 +1148,13 @@ centerSessionManager.startup(); // console.log(pdu); // }); +session.on(ClientSession.ANY_PDU_EVENT, (pdu) => { + if (pdu.command.includes('enquire')) { + return; + } + console.log(pdu); +}); + new WSServer(); new HTTPServer(); @@ -1143,8 +1164,8 @@ function cleanup() { process.exit(0); } -process.on('exit', cleanup); -process.on('SIGINT', cleanup); -process.on('SIGUSR1', cleanup); -process.on('SIGUSR2', cleanup); -process.on('uncaughtException', cleanup); \ No newline at end of file +// process.on('exit', cleanup); +// process.on('SIGINT', cleanup); +// process.on('SIGUSR1', cleanup); +// process.on('SIGUSR2', cleanup); +// process.on('uncaughtException', cleanup); \ No newline at end of file