Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
Muraveiko committed Nov 2, 2019
1 parent 060a9a0 commit d888cb3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea/
/vendor/
/dist/server.json
Binary file added dist/rawbt.phar
Binary file not shown.
51 changes: 29 additions & 22 deletions src/server.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?php
/**
* WebSocket server for RawBT
*
* Based on PHP POS Print (Local Server)
* https://github.com/Tecdiary/ppp
* MIT License
*
* Modified by 402d (oleg@muraveyko.ru)
*/

require_once __DIR__ . '/../vendor/autoload.php';

use Noodlehaus\Config;
use Noodlehaus\Parser\Json;

use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
use Mike42\Escpos\PrintConnectors\UriPrintConnector;
Expand All @@ -27,29 +36,28 @@
$data = $bucket->getData();
echo '> Received request ', "\n";

$toprint = $data['message'];
$toprint = str_replace("intent:base64,","",$toprint);
$toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;","",$toprint);
$toprint = base64_decode($toprint);
$toprint = $data['message'];
$toprint = str_replace("intent:base64,", "", $toprint);
$toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;", "", $toprint);
$toprint = base64_decode($toprint);


$conf = Config::load('server.json');
$conf = Config::load('server.json');

if ($conf->get('PrintConnector.Type') == 'Network') {
set_time_limit($conf->get('PrintConnector.Params.timeout',10)+10);
$connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip','127.0.0.1'),$conf->get('PrintConnector.Params.port',9100),$conf->get('PrintConnector.Params.timeout',10));
} elseif ($conf->get('PrintConnector.Type') == 'Uri') {
$connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri','tcp://127.0.0.1:9100'));
} elseif ($conf->get('PrintConnector.Type') == 'Cups') {
$connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.dest'));
} elseif ($conf->get('PrintConnector.Type') == 'File') {
$connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.filename'));
} else {
// $conf->get('PrintConnector.Type') == 'Windows'
$connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest','LPT1'));
}
$connector -> write($toprint);
$connector -> finalize();
if ($conf->get('PrintConnector.Type') == 'Network') {
set_time_limit($conf->get('PrintConnector.Params.timeout', 10) + 10);
$connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip', '127.0.0.1'), $conf->get('PrintConnector.Params.port', 9100), $conf->get('PrintConnector.Params.timeout', 10));
} elseif ($conf->get('PrintConnector.Type') == 'Uri') {
$connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri', 'tcp://127.0.0.1:9100'));
} elseif ($conf->get('PrintConnector.Type') == 'Cups') {
$connector = new CupsPrintConnector($conf->get('PrintConnector.Params.dest'));
} elseif ($conf->get('PrintConnector.Type') == 'File') {
$connector = new FilePrintConnector($conf->get('PrintConnector.Params.filename'));
} else { // 'Windows'
$connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest', 'LPT1'));
}
$connector->write($toprint);
$connector->finalize();
echo '> Done print task ', "\n";
return;
});
Expand All @@ -65,7 +73,6 @@
} catch (Exception $e) {
echo '> Error occurred, server stopped. ', $e->getMessage(), "\n";
}

} catch (Exception $e) {
echo '> Error: ', $e->getMessage(), "\n";
}
Expand Down

0 comments on commit d888cb3

Please sign in to comment.