sim800
Version:
A modern and opiniated module for SIM800 GSM modems ( SIM800 / SIM800L ).
65 lines • 3.3 kB
JavaScript
;
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sim800Sms = void 0;
const rxjs_1 = require("rxjs");
const handle_sms_stream_after_pdu_part_1 = require("../helpers/handle-sms-stream-after-pdu-part");
const cmgs_command_1 = require("./cmgs-command");
const generate_pdu_data_1 = require("../helpers/generate-pdu-data");
const input_command_1 = require("./input-command");
class Sim800Sms {
constructor(client, data) {
this.client = client;
this.data = data;
this.result$ = new rxjs_1.Subject();
}
async execute() {
var _a, e_1, _b, _c;
const compositeId = [];
try {
const data = (0, generate_pdu_data_1.generatePduData)(this.data.number, this.data.text, this.data.deliveryReport);
try {
// We send each pdu part
for (var _d = true, data_1 = __asyncValues(data), data_1_1; data_1_1 = await data_1.next(), _a = data_1_1.done, !_a; _d = true) {
_c = data_1_1.value;
_d = false;
const pduPart = _c;
await this.client.send(new cmgs_command_1.CmgsCommand(pduPart.tpdu_length));
const commandResult = (await this.client.send(new input_command_1.InputCommand(pduPart.smsc_tpdu), { raw: true }));
const messageReference = parseInt(commandResult[0].split(':')[1].trim(), 10);
compositeId.push(messageReference);
// If there is only one part, we can push the unique part as a sms
(0, handle_sms_stream_after_pdu_part_1.handleSmsStreamAfterPduPart)(data, this.client.smsStream$, this.client.outboxSpooler, compositeId, this.data.text, this.data.deliveryReport, this.data.number, messageReference);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = data_1.return)) await _b.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
this.result = compositeId;
this.result$.next(compositeId);
this.result$.complete();
}
catch (err) {
if (err instanceof Error) {
this.error = err;
}
this.result$.error(err);
this.result$.complete();
}
finally {
this.client.smsQueuePing$.next();
}
}
}
exports.Sim800Sms = Sim800Sms;
//# sourceMappingURL=sim800-sms.js.map