Commit 71a0b3ff60b7492030fe39ddaf2a8a1d01bc7820

Authored by Adhidarma Hadiwinoto
1 parent 65f1ac9a4c
Exists in master

Tamabahan pilihan untuk reset sesi USSD

Showing 2 changed files with 6 additions and 10 deletions Side-by-side Diff

lib/http-command-server/router-ussd.js
... ... @@ -12,9 +12,10 @@ module.exports = router;
12 12 * @param {object} req - Objek request Express
13 13 *
14 14 * Pilihan req.query.include_cusd2:
  15 + * -1: sebelum
15 16 * 0: tidak (default)
16 17 * 1: sesudah
17   - * -1: sebelum
  18 + * 2: sebelum dan sesudah
18 19 *
19 20 * @param {object} req.query - Objek query string request Express
20 21 * @param {string} req.query.code - Kode USSD yang ingin dieksekusi
... ... @@ -5,9 +5,6 @@ const MAX_LAST_DATA_AGE_MS = 3 * 60 * 1000;
5 5 const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r/;
6 6 // const REGEX_WAIT_FOR_OK_OR_ERROR_USSD = /\n(?:OK|ERROR)\r/;
7 7  
8   -const CUSD2_BEFORE = -1;
9   -const CUSD2_AFTER = 1;
10   -
11 8 const moment = require('moment');
12 9 const SerialPort = require('serialport');
13 10 const ParserReadline = require('@serialport/parser-readline');
... ... @@ -313,9 +310,10 @@ async function sendSMS(destination, msg) {
313 310 * Ekseksusi kode USSD.
314 311 *
315 312 * Pilihan includeCUSD2:
  313 + * -1: sebelum
316 314 * 0: tidak (default)
317 315 * 1: sesudah
318   - * -1: sebelum
  316 + * 2: sebelum dan sesudah
319 317 *
320 318 * @param {string} code - Kode USSD
321 319 * @param {number} [includeCUSD2=0] - Apakah ingin otomatis memasukkan CUSD=2
... ... @@ -340,7 +338,7 @@ function executeUSSD(code, includeCUSD2) {
340 338 logger.verbose('Waiting for command lock to execute USSD');
341 339 await mutex.setLockWaitForCommand();
342 340  
343   - if (includeCUSD2 === CUSD2_BEFORE) {
  341 + if (includeCUSD2 === -1 || includeCUSD2 === 2) {
344 342 logger.info('Terminating existing USSD session');
345 343 await mutex.setLockWaitForSubCommand();
346 344 port.pipe(parserCUSD2);
... ... @@ -351,7 +349,7 @@ function executeUSSD(code, includeCUSD2) {
351 349 port.pipe(parserMain);
352 350 await writeToPort(`AT+CUSD=1,"${code}",15\r`);
353 351  
354   - if (includeCUSD2 === CUSD2_AFTER) {
  352 + if (includeCUSD2 === 1 || includeCUSD2 === 2) {
355 353 logger.info('Terminating existing USSD session');
356 354 await mutex.setLockWaitForSubCommand();
357 355 port.pipe(parserCUSD2);
... ... @@ -421,9 +419,6 @@ function init() {
421 419  
422 420 init();
423 421  
424   -exports.CUSD2_BEFORE = CUSD2_BEFORE;
425   -exports.CUSD2_AFTER = CUSD2_AFTER;
426   -
427 422 exports.modemInfo = modemInfo;
428 423 exports.sendSMS = sendSMS;
429 424 exports.executeUSSD = executeUSSD;