@hardwarebridge/client 1.0.0 โ†’ 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +546 -0
  3. package/package.json +6 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Azlam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,546 @@
1
+ # ๐Ÿ”Œ Hardware Bridge Client
2
+
3
+ [![npm version](https://badge.fury.io/js/%40hardwarebridge%2Fclient.svg)](https://badge.fury.io/js/%40hardwarebridge%2Fclient)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
6
+
7
+ A professional TypeScript client library for connecting to Hardware Bridge WebSocket services. Control hardware devices including printers, serial ports, and USB HID devices with ease.
8
+
9
+ ## ๐Ÿš€ Quick Start
10
+
11
+ ```bash
12
+ npm install @hardwarebridge/client
13
+ ```
14
+
15
+ ```typescript
16
+ import { HardwareBridgeClient } from '@hardwarebridge/client';
17
+
18
+ const client = new HardwareBridgeClient({
19
+ url: 'ws://localhost:8443',
20
+ autoReconnect: true
21
+ });
22
+
23
+ await client.connect();
24
+ const devices = await client.enumerateDevices();
25
+ ```
26
+
27
+ ## ๐Ÿ“‹ Table of Contents
28
+
29
+ - [Features](#features)
30
+ - [Installation](#installation)
31
+ - [Basic Usage](#basic-usage)
32
+ - [API Reference](#api-reference)
33
+ - [Hardware Support](#hardware-support)
34
+ - [Examples](#examples)
35
+ - [TypeScript Support](#typescript-support)
36
+ - [Error Handling](#error-handling)
37
+ - [Testing](#testing)
38
+ - [Contributing](#contributing)
39
+ - [License](#license)
40
+ - [Support](#support)
41
+
42
+ ## โœจ Features
43
+
44
+ - ๐Ÿ”Œ **WebSocket Communication** - Real-time connection to Hardware Bridge server
45
+ - ๐Ÿ–จ๏ธ **Printer Support** - ESC/POS, ZPL, EPL protocols
46
+ - ๐Ÿ”Œ **Serial Port Control** - Full serial communication capabilities
47
+ - ๐Ÿ“ฑ **USB HID Devices** - Human Interface Device communication
48
+ - ๐Ÿ“ฆ **Queue Management** - Built-in job queuing system
49
+ - ๐Ÿ”’ **TypeScript Support** - Full type definitions and IntelliSense
50
+ - ๐Ÿ”„ **Auto-reconnection** - Robust connection handling
51
+ - ๐Ÿ“Š **Device Discovery** - Automatic device enumeration
52
+ - โšก **Multi-format Support** - CommonJS, ES Modules, UMD builds
53
+
54
+ ## ๐Ÿ“ฆ Installation
55
+
56
+ ```bash
57
+ # npm
58
+ npm install @hardwarebridge/client
59
+
60
+ # yarn
61
+ yarn add @hardwarebridge/client
62
+
63
+ # pnpm
64
+ pnpm add @hardwarebridge/client
65
+ ```
66
+
67
+ ## ๐Ÿ”ง Basic Usage
68
+
69
+ ### Connecting to the Server
70
+
71
+ ```typescript
72
+ import { HardwareBridgeClient } from '@hardwarebridge/client';
73
+
74
+ const client = new HardwareBridgeClient({
75
+ url: 'ws://localhost:8443',
76
+ autoReconnect: true,
77
+ reconnectInterval: 5000
78
+ });
79
+
80
+ // Connect to the server
81
+ await client.connect();
82
+ console.log('Connected to Hardware Bridge server!');
83
+ ```
84
+
85
+ ### Device Discovery
86
+
87
+ ```typescript
88
+ // Discover all available devices
89
+ const devices = await client.enumerateDevices();
90
+ console.log(`Found ${devices.length} devices`);
91
+
92
+ devices.forEach(device => {
93
+ console.log(`${device.name} (${device.type}) - ${device.status}`);
94
+ });
95
+
96
+ // Get detailed information about a specific device
97
+ const printer = await client.getDevice('printer_test1');
98
+ console.log('Printer details:', printer);
99
+ ```
100
+
101
+ ### Printer Operations
102
+
103
+ ```typescript
104
+ // Get printer status
105
+ const status = await client.getPrinterStatus('printer_test1');
106
+ console.log('Printer status:', status.status);
107
+
108
+ // Get printer capabilities
109
+ const capabilities = await client.getPrinterCapabilities('printer_test1');
110
+ console.log('Supported protocols:', capabilities.supportedProtocols);
111
+
112
+ // Print content
113
+ const printResult = await client.print('printer_test1', 'Hello World!', 'raw');
114
+ console.log('Print job:', printResult.jobId);
115
+ ```
116
+
117
+ ### Queue Management
118
+
119
+ ```typescript
120
+ // Get queue status
121
+ const queueStatus = await client.getQueueStatus();
122
+ console.log('Queue status:', queueStatus);
123
+
124
+ // Get queue jobs
125
+ const jobs = await client.getQueueJobs();
126
+ console.log(`Found ${jobs.length} jobs in queue`);
127
+ ```
128
+
129
+ ## ๐Ÿ“š API Reference
130
+
131
+ ### HardwareBridgeClient
132
+
133
+ #### Constructor Options
134
+
135
+ ```typescript
136
+ interface ClientOptions {
137
+ url: string; // WebSocket URL
138
+ autoReconnect?: boolean; // Auto-reconnect on disconnect
139
+ reconnectInterval?: number; // Reconnection interval in ms
140
+ timeout?: number; // Request timeout in ms
141
+ }
142
+ ```
143
+
144
+ #### Methods
145
+
146
+ ### Connection Management
147
+
148
+ ```typescript
149
+ // Connect to server
150
+ await client.connect();
151
+
152
+ // Disconnect from server
153
+ await client.disconnect();
154
+
155
+ // Check connection status
156
+ const isConnected = client.isConnected();
157
+ ```
158
+
159
+ ### Device Operations
160
+
161
+ ```typescript
162
+ // Enumerate all devices
163
+ const devices = await client.enumerateDevices();
164
+
165
+ // Get specific device info
166
+ const device = await client.getDevice(deviceId);
167
+
168
+ // Listen for device events
169
+ client.onDeviceEvent((event) => {
170
+ console.log('Device event:', event);
171
+ });
172
+ ```
173
+
174
+ ### Printer Operations
175
+
176
+ ```typescript
177
+ // Get printer status
178
+ const status = await client.getPrinterStatus(deviceId);
179
+
180
+ // Get printer capabilities
181
+ const capabilities = await client.getPrinterCapabilities(deviceId);
182
+
183
+ // Print content
184
+ const result = await client.print(deviceId, data, format);
185
+ ```
186
+
187
+ ### Queue Operations
188
+
189
+ ```typescript
190
+ // Get queue status
191
+ const status = await client.getQueueStatus();
192
+
193
+ // Get queue jobs
194
+ const jobs = await client.getQueueJobs({
195
+ deviceId?: string,
196
+ status?: string,
197
+ limit?: number
198
+ });
199
+
200
+ // Cancel a queue job
201
+ await client.cancelQueueJob(jobId);
202
+ ```
203
+
204
+ ## ๐Ÿ–จ๏ธ Hardware Support
205
+
206
+ ### Supported Protocols
207
+
208
+ - **ESC/POS** - Epson Standard Code for Point of Sale
209
+ - **ZPL** - Zebra Programming Language
210
+ - **EPL** - Eltron Programming Language
211
+ - **Raw** - Direct data transmission
212
+
213
+ ### Device Types
214
+
215
+ - **Printers** - Thermal, label, receipt printers
216
+ - **Serial Ports** - COM ports, UART communication
217
+ - **USB HID** - Human Interface Devices
218
+ - **Custom Devices** - Extensible device support
219
+
220
+ ## ๐Ÿ“– Examples
221
+
222
+ ### Complete Printer Example
223
+
224
+ ```typescript
225
+ import { HardwareBridgeClient } from '@hardwarebridge/client';
226
+
227
+ async function printReceipt() {
228
+ const client = new HardwareBridgeClient({
229
+ url: 'ws://localhost:8443'
230
+ });
231
+
232
+ try {
233
+ await client.connect();
234
+
235
+ // Find printer
236
+ const devices = await client.enumerateDevices();
237
+ const printer = devices.find(d => d.type === 'printer');
238
+
239
+ if (!printer) {
240
+ throw new Error('No printer found');
241
+ }
242
+
243
+ // Print receipt in ESC/POS format
244
+ const receipt = `
245
+ RECEIPT #12345
246
+ ================
247
+ Date: ${new Date().toLocaleString()}
248
+
249
+ Item Qty Price
250
+ Coffee 2 $5.00
251
+ Sandwich 1 $8.50
252
+ ----------------
253
+ Total: $13.50
254
+
255
+ Thank you!
256
+ ================
257
+ `;
258
+
259
+ const result = await client.print(printer.id, receipt, 'escpos');
260
+ console.log('Receipt printed:', result.jobId);
261
+
262
+ } catch (error) {
263
+ console.error('Print error:', error);
264
+ } finally {
265
+ await client.disconnect();
266
+ }
267
+ }
268
+
269
+ printReceipt();
270
+ ```
271
+
272
+ ### Serial Port Communication
273
+
274
+ ```typescript
275
+ async function serialCommunication() {
276
+ const client = new HardwareBridgeClient({
277
+ url: 'ws://localhost:8443'
278
+ });
279
+
280
+ await client.connect();
281
+
282
+ // Find serial device
283
+ const devices = await client.enumerateDevices();
284
+ const serialDevice = devices.find(d => d.type === 'serial');
285
+
286
+ if (serialDevice) {
287
+ // Open serial port
288
+ await client.openSerialPort(serialDevice.id, {
289
+ baudRate: 9600,
290
+ dataBits: 8,
291
+ parity: 'none',
292
+ stopBits: 1
293
+ });
294
+
295
+ // Send data
296
+ await client.sendSerialData(serialDevice.id, 'Hello Serial!');
297
+
298
+ // Receive data
299
+ const data = await client.receiveSerialData(serialDevice.id);
300
+ console.log('Received:', data);
301
+ }
302
+
303
+ await client.disconnect();
304
+ }
305
+ ```
306
+
307
+ ### Queue Management Example
308
+
309
+ ```typescript
310
+ async function queueManagement() {
311
+ const client = new HardwareBridgeClient({
312
+ url: 'ws://localhost:8443'
313
+ });
314
+
315
+ await client.connect();
316
+
317
+ // Get queue status
318
+ const status = await client.getQueueStatus();
319
+ console.log('Queue status:', {
320
+ total: status.totalJobs,
321
+ pending: status.pendingJobs,
322
+ processing: status.processingJobs,
323
+ completed: status.completedJobs
324
+ });
325
+
326
+ // Get recent jobs
327
+ const jobs = await client.getQueueJobs({ limit: 10 });
328
+ jobs.forEach(job => {
329
+ console.log(`${job.id}: ${job.operation} - ${job.status}`);
330
+ });
331
+
332
+ await client.disconnect();
333
+ }
334
+ ```
335
+
336
+ ## ๐ŸŽจ Print Format Examples
337
+
338
+ ### ESC/POS (Receipt Format)
339
+ ```typescript
340
+ const escposReceipt = `
341
+ RECEIPT #12345
342
+ ================
343
+ Date: ${new Date().toLocaleString()}
344
+
345
+ Item Qty Price
346
+ Coffee 2 $5.00
347
+ Sandwich 1 $8.50
348
+ Cookie 3 $4.50
349
+ ----------------
350
+ Total: $18.00
351
+
352
+ Thank you!
353
+ ================
354
+ `;
355
+
356
+ await client.print(printerId, escposReceipt, 'escpos');
357
+ ```
358
+
359
+ ### ZPL (Zebra Programming Language)
360
+ ```typescript
361
+ const zplLabel = `
362
+ ^XA
363
+ ^FO50,30^ADN,36,20^FDHardware Bridge Demo^FS
364
+ ^FO50,80^ADN,18,10^FDZPL Format Test^FS
365
+ ^FO50,120^BCN,80,Y,N,N^FD123456789^FS
366
+ ^XZ
367
+ `;
368
+
369
+ await client.print(printerId, zplLabel, 'zpl');
370
+ ```
371
+
372
+ ### EPL (Eltron Programming Language)
373
+ ```typescript
374
+ const eplLabel = `
375
+ N
376
+ q609
377
+ Q203,26
378
+ A5,26,0,2,1,1,N,"Hardware Bridge Demo"
379
+ A5,56,0,2,1,1,N,"EPL Format Test"
380
+ B5,86,0,1,2,2,100,B,"TEST123456"
381
+ P1
382
+ `;
383
+
384
+ await client.print(printerId, eplLabel, 'epl');
385
+ ```
386
+
387
+ ## ๐Ÿ”’ Error Handling
388
+
389
+ ```typescript
390
+ import { HardwareBridgeClient, HardwareBridgeError } from '@hardwarebridge/client';
391
+
392
+ const client = new HardwareBridgeClient({
393
+ url: 'ws://localhost:8443',
394
+ autoReconnect: true
395
+ });
396
+
397
+ // Handle connection errors
398
+ client.onConnectionStateChange((connected) => {
399
+ if (!connected) {
400
+ console.log('Connection lost, will attempt to reconnect...');
401
+ }
402
+ });
403
+
404
+ // Handle device events
405
+ client.onDeviceEvent((event) => {
406
+ console.log('Device event:', event);
407
+ });
408
+
409
+ // Handle errors gracefully
410
+ try {
411
+ await client.connect();
412
+
413
+ // Your code here
414
+ const devices = await client.enumerateDevices();
415
+
416
+ } catch (error) {
417
+ if (error instanceof HardwareBridgeError) {
418
+ console.error('Hardware Bridge Error:', error.message);
419
+ console.error('Error Code:', error.code);
420
+ } else {
421
+ console.error('Unknown Error:', error);
422
+ }
423
+ } finally {
424
+ await client.disconnect();
425
+ }
426
+ ```
427
+
428
+ ## ๐ŸŒ Browser Usage
429
+
430
+ ```html
431
+ <!DOCTYPE html>
432
+ <html>
433
+ <head>
434
+ <title>Hardware Bridge Demo</title>
435
+ </head>
436
+ <body>
437
+ <h1>Hardware Bridge Client Demo</h1>
438
+ <button id="connect">Connect</button>
439
+ <button id="print">Print Test</button>
440
+ <div id="status">Disconnected</div>
441
+ <div id="devices"></div>
442
+
443
+ <script type="module">
444
+ import { HardwareBridgeClient } from 'https://unpkg.com/@hardwarebridge/client@latest/dist/index.esm.js';
445
+
446
+ const client = new HardwareBridgeClient({
447
+ url: 'ws://localhost:8443'
448
+ });
449
+
450
+ document.getElementById('connect').addEventListener('click', async () => {
451
+ try {
452
+ await client.connect();
453
+ document.getElementById('status').textContent = 'Connected!';
454
+
455
+ const devices = await client.enumerateDevices();
456
+ document.getElementById('devices').innerHTML =
457
+ devices.map(d => `<p>${d.name} (${d.type})</p>`).join('');
458
+ } catch (error) {
459
+ document.getElementById('status').textContent = 'Connection failed: ' + error.message;
460
+ }
461
+ });
462
+
463
+ document.getElementById('print').addEventListener('click', async () => {
464
+ try {
465
+ const devices = await client.enumerateDevices();
466
+ const printer = devices.find(d => d.type === 'printer');
467
+
468
+ if (printer) {
469
+ await client.print(printer.id, 'Hello from Browser!', 'raw');
470
+ alert('Printed successfully!');
471
+ } else {
472
+ alert('No printer found');
473
+ }
474
+ } catch (error) {
475
+ alert('Print failed: ' + error.message);
476
+ }
477
+ });
478
+ </script>
479
+ </body>
480
+ </html>
481
+ ```
482
+
483
+ ## ๐Ÿ› ๏ธ Configuration
484
+
485
+ ### Server Configuration
486
+
487
+ ```typescript
488
+ const client = new HardwareBridgeClient({
489
+ url: 'ws://localhost:8443', // WebSocket URL
490
+ autoReconnect: true, // Auto-reconnect on disconnect
491
+ reconnectInterval: 5000, // Reconnection interval (ms)
492
+ timeout: 10000, // Request timeout (ms)
493
+ maxRetries: 3, // Maximum reconnection attempts
494
+ enableLogging: true // Enable debug logging
495
+ });
496
+ ```
497
+
498
+ ### Security Configuration
499
+
500
+ ```typescript
501
+ const client = new HardwareBridgeClient({
502
+ url: 'wss://secure-server.com:8443', // Use WSS for secure connections
503
+ authToken: 'your-auth-token', // Authentication token
504
+ validateCertificate: true // Validate SSL certificates
505
+ });
506
+ ```
507
+
508
+ ## ๐Ÿงช Testing
509
+
510
+ ```bash
511
+ # Run the test applications
512
+ cd src/TestApp
513
+ npm install
514
+ npm start
515
+
516
+ # Or run specific tests
517
+ node simple-test-app.js
518
+ node enhanced-test-app.js
519
+ ```
520
+
521
+ ## ๐Ÿค Contributing
522
+
523
+ Contributions are welcome! Please feel free to submit a Pull Request.
524
+
525
+ 1. Fork the repository: `https://github.com/me-azlam-kp/hardwarebridge.git`
526
+ 2. Create your feature branch: `git checkout -b feature/amazing-feature`
527
+ 3. Commit your changes: `git commit -m 'Add amazing feature'`
528
+ 4. Push to the branch: `git push origin feature/amazing-feature`
529
+ 5. Open a Pull Request
530
+
531
+ ## ๐Ÿ“„ License
532
+
533
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
534
+
535
+ Copyright (c) 2024 Azlam
536
+
537
+ ## ๐Ÿ†˜ Support
538
+
539
+ For support and questions:
540
+ - **Issues**: [Create an issue](https://github.com/me-azlam-kp/hardwarebridge/issues) in the repository
541
+ - **Documentation**: Check the [docs folder](https://github.com/me-azlam-kp/hardwarebridge/tree/main/docs) for detailed guides
542
+ - **Repository**: [https://github.com/me-azlam-kp/hardwarebridge](https://github.com/me-azlam-kp/hardwarebridge)
543
+
544
+ ---
545
+
546
+ **Developed by Azlam**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardwarebridge/client",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "TypeScript client library for Hardware Bridge WebSocket service",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "typescript",
39
39
  "rxjs"
40
40
  ],
41
- "author": "Hardware Bridge Team",
41
+ "author": "Azlam",
42
42
  "license": "MIT",
43
43
  "dependencies": {
44
44
  "rxjs": "^7.0.0",
@@ -69,10 +69,11 @@
69
69
  },
70
70
  "repository": {
71
71
  "type": "git",
72
- "url": "https://github.com/hardwarebridge/client.git"
72
+ "url": "https://github.com/me-azlam-kp/hardwarebridge.git",
73
+ "directory": "src/BridgeClient"
73
74
  },
74
75
  "bugs": {
75
- "url": "https://github.com/hardwarebridge/client/issues"
76
+ "url": "https://github.com/me-azlam-kp/hardwarebridge/issues"
76
77
  },
77
- "homepage": "https://github.com/hardwarebridge/client#readme"
78
+ "homepage": "https://github.com/me-azlam-kp/hardwarebridge#readme"
78
79
  }