capacitor-zebra-printer
Version:
Capacitor plugin to send ZPL messages to Zebra printers
50 lines (41 loc) • 1.55 kB
JavaScript
var capacitorCapacitorZebraPrinter = (function (exports, core) {
'use strict';
const CapacitorZebraPrinter = core.registerPlugin('CapacitorZebraPrinter', {
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorZebraPrinterWeb()),
});
const fetchWithTimeout = (request, timeout = 30000) => {
return Promise.race([
fetch(request),
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)),
]);
};
class CapacitorZebraPrinterWeb extends core.WebPlugin {
async echo(options) {
console.log('ECHO', options);
return options;
}
async print(options) {
const request = new Request(`http://${options.ip}:${options.port}`, {
method: 'POST',
mode: 'no-cors',
cache: 'no-cache',
body: options.zpl,
});
return await fetchWithTimeout(request)
.then(() => {
return { value: 'success' };
})
.catch(() => {
return { value: 'error' };
});
}
}
var web = /*#__PURE__*/Object.freeze({
__proto__: null,
CapacitorZebraPrinterWeb: CapacitorZebraPrinterWeb
});
exports.CapacitorZebraPrinter = CapacitorZebraPrinter;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({}, capacitorExports);
//# sourceMappingURL=plugin.js.map