UNPKG

capacitor-zebra-printer

Version:

Capacitor plugin to send ZPL messages to Zebra printers

47 lines (39 loc) 1.34 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var core = require('@capacitor/core'); 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; //# sourceMappingURL=plugin.cjs.js.map