|
1 | 1 | <?php
|
| 2 | +/** |
| 3 | + * WebSocket server for RawBT |
| 4 | + * |
| 5 | + * Based on PHP POS Print (Local Server) |
| 6 | + * https://github.com/Tecdiary/ppp |
| 7 | + * MIT License |
| 8 | + * |
| 9 | + * Modified by 402d (oleg@muraveyko.ru) |
| 10 | + */ |
| 11 | + |
2 | 12 | require_once __DIR__ . '/../vendor/autoload.php';
|
3 | 13 |
|
4 | 14 | use Noodlehaus\Config;
|
5 |
| -use Noodlehaus\Parser\Json; |
6 | 15 |
|
7 | 16 | use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
|
8 | 17 | use Mike42\Escpos\PrintConnectors\UriPrintConnector;
|
|
27 | 36 | $data = $bucket->getData();
|
28 | 37 | echo '> Received request ', "\n";
|
29 | 38 |
|
30 |
| - $toprint = $data['message']; |
31 |
| - $toprint = str_replace("intent:base64,","",$toprint); |
32 |
| - $toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;","",$toprint); |
33 |
| - $toprint = base64_decode($toprint); |
| 39 | + $toprint = $data['message']; |
| 40 | + $toprint = str_replace("intent:base64,", "", $toprint); |
| 41 | + $toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;", "", $toprint); |
| 42 | + $toprint = base64_decode($toprint); |
34 | 43 |
|
35 | 44 |
|
36 |
| - $conf = Config::load('server.json'); |
| 45 | + $conf = Config::load('server.json'); |
37 | 46 |
|
38 |
| - if ($conf->get('PrintConnector.Type') == 'Network') { |
39 |
| - set_time_limit($conf->get('PrintConnector.Params.timeout',10)+10); |
40 |
| - $connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip','127.0.0.1'),$conf->get('PrintConnector.Params.port',9100),$conf->get('PrintConnector.Params.timeout',10)); |
41 |
| - } elseif ($conf->get('PrintConnector.Type') == 'Uri') { |
42 |
| - $connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri','tcp://127.0.0.1:9100')); |
43 |
| - } elseif ($conf->get('PrintConnector.Type') == 'Cups') { |
44 |
| - $connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.dest')); |
45 |
| - } elseif ($conf->get('PrintConnector.Type') == 'File') { |
46 |
| - $connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.filename')); |
47 |
| - } else { |
48 |
| - // $conf->get('PrintConnector.Type') == 'Windows' |
49 |
| - $connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest','LPT1')); |
50 |
| - } |
51 |
| - $connector -> write($toprint); |
52 |
| - $connector -> finalize(); |
| 47 | + if ($conf->get('PrintConnector.Type') == 'Network') { |
| 48 | + set_time_limit($conf->get('PrintConnector.Params.timeout', 10) + 10); |
| 49 | + $connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip', '127.0.0.1'), $conf->get('PrintConnector.Params.port', 9100), $conf->get('PrintConnector.Params.timeout', 10)); |
| 50 | + } elseif ($conf->get('PrintConnector.Type') == 'Uri') { |
| 51 | + $connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri', 'tcp://127.0.0.1:9100')); |
| 52 | + } elseif ($conf->get('PrintConnector.Type') == 'Cups') { |
| 53 | + $connector = new CupsPrintConnector($conf->get('PrintConnector.Params.dest')); |
| 54 | + } elseif ($conf->get('PrintConnector.Type') == 'File') { |
| 55 | + $connector = new FilePrintConnector($conf->get('PrintConnector.Params.filename')); |
| 56 | + } else { // 'Windows' |
| 57 | + $connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest', 'LPT1')); |
| 58 | + } |
| 59 | + $connector->write($toprint); |
| 60 | + $connector->finalize(); |
53 | 61 | echo '> Done print task ', "\n";
|
54 | 62 | return;
|
55 | 63 | });
|
|
65 | 73 | } catch (Exception $e) {
|
66 | 74 | echo '> Error occurred, server stopped. ', $e->getMessage(), "\n";
|
67 | 75 | }
|
68 |
| - |
69 | 76 | } catch (Exception $e) {
|
70 | 77 | echo '> Error: ', $e->getMessage(), "\n";
|
71 | 78 | }
|
|
0 commit comments