diff --git a/public/pos/epos-print.js b/public/pos/epos-print.js index 0f0e646..702ebbe 100644 --- a/public/pos/epos-print.js +++ b/public/pos/epos-print.js @@ -120,5 +120,22 @@ window.EposPrint = (function () { return `${parts.join('')}`; } - return { getSettings, setSettings, imageToRaster, buildEposXml }; + async function printViaNetwork(ip, xml) { + const res = await fetch(`https://${ip}/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000`, { + method: 'POST', + headers: { 'Content-Type': 'text/xml; charset=utf-8', 'SOAPAction': '""' }, + body: xml + }); + if (!res.ok) throw new Error('Printer HTTP error: ' + res.status); + const text = await res.text(); + const doc = new DOMParser().parseFromString(text, 'text/xml'); + const response = doc.getElementsByTagName('response')[0]; + const success = response && response.getAttribute('success') === 'true'; + if (!success) { + const code = response ? response.getAttribute('code') : null; + throw new Error('Printer rejected job' + (code ? ' (code: ' + code + ')' : '')); + } + } + + return { getSettings, setSettings, imageToRaster, buildEposXml, printViaNetwork }; })();