From 5a91776f21fc4155244b7bbc6fcc1af21d6b56af Mon Sep 17 00:00:00 2001 From: erikn69 Date: Wed, 13 Nov 2024 15:44:48 -0500 Subject: [PATCH] Fix socket response --- ZplEscPrinter/js/main.js | 19 ++++++++++++++----- package.json | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ZplEscPrinter/js/main.js b/ZplEscPrinter/js/main.js index 5dde90e..2124210 100644 --- a/ZplEscPrinter/js/main.js +++ b/ZplEscPrinter/js/main.js @@ -27,10 +27,13 @@ const defaults = { }; $(function () { - $(window).bind('focus blur', function () { - $('#panel-head').toggleClass('panel-heading-blur'); + $(window).bind('focus', function () { + $('#panel-head').removeClass('panel-heading-blur'); + }); + $(window).bind('blur', function () { + if (document.activeElement && document.activeElement.tagName === 'IFRAME') return; + $('#panel-head').addClass('panel-heading-blur'); }); - // todo only on first run if (!global.localStorage.getItem('isOn')) { Object.entries(defaults).forEach(function ([k, v]) { @@ -248,13 +251,19 @@ function startTcpServer() { peerAddress: sock.remoteAddress, peerPort: sock.remotePort }; - sock.write(JSON.stringify({success: true})); sock.on('data', async function (data) { notify('{0} bytes received from Client: {1} Port: {2}'.format(data.length, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000); //console.log(String.fromCharCode.apply(null, new Uint8Array(data))); const regex = /POST.*\r\n\r\n/gs; - const code = (data || '').replace(regex,''); + if (regex.test(data)) { + const response = JSON.stringify({success: true}); + sock.write('HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: ' + Buffer.byteLength(response) + '\r\n\r\n' + response); + data = data.replace(regex,''); + } + sock.end(); + + const code = data + ''; if (code.includes('Host:') && code.includes('Connection: keep-alive') && code.includes('HTTP')) { console.log('It\'s an ajax call'); return; diff --git a/package.json b/package.json index ed55bf0..adb24d3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zpl-escpos-printer", "productName": "Zpl/EscPos Printer", - "version": "3.0.4", + "version": "3.0.5", "description": "Printer emulator for Zpl/EscPos rendering engine.", "main": "main.js", "scripts": {