@hardwarebridge/client 1.0.0
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.
- package/dist/index.d.ts +349 -0
- package/dist/index.esm.js +438 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +442 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +448 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +78 -0
- package/src/__tests__/hardware-bridge-client.test.ts +248 -0
- package/src/__tests__/types.test.ts +153 -0
- package/src/__tests__/websocket-client.test.ts +198 -0
- package/src/core/hardware-bridge-client.ts +306 -0
- package/src/core/websocket-client.ts +337 -0
- package/src/index.ts +37 -0
- package/src/types.ts +187 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
interface DeviceInfo {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
type: 'printer' | 'serial' | 'usbhid';
|
|
5
|
+
status: 'available' | 'connected' | 'error';
|
|
6
|
+
manufacturer: string;
|
|
7
|
+
model: string;
|
|
8
|
+
serialNumber: string;
|
|
9
|
+
properties: Record<string, any>;
|
|
10
|
+
lastSeen: Date;
|
|
11
|
+
isConnected: boolean;
|
|
12
|
+
connectionId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface PrinterDevice extends DeviceInfo {
|
|
15
|
+
supportedProtocols: string[];
|
|
16
|
+
maxPrintWidth: number;
|
|
17
|
+
supportsColor: boolean;
|
|
18
|
+
supportsDuplex: boolean;
|
|
19
|
+
maxResolution: number;
|
|
20
|
+
currentStatus: string;
|
|
21
|
+
jobsInQueue: number;
|
|
22
|
+
}
|
|
23
|
+
interface SerialPortDevice extends DeviceInfo {
|
|
24
|
+
portName: string;
|
|
25
|
+
baudRate: number;
|
|
26
|
+
parity: string;
|
|
27
|
+
dataBits: number;
|
|
28
|
+
stopBits: string;
|
|
29
|
+
flowControl: string;
|
|
30
|
+
isOpen: boolean;
|
|
31
|
+
bytesToRead: number;
|
|
32
|
+
bytesToWrite: number;
|
|
33
|
+
}
|
|
34
|
+
interface UsbHidDevice extends DeviceInfo {
|
|
35
|
+
vendorId: number;
|
|
36
|
+
productId: number;
|
|
37
|
+
version: number;
|
|
38
|
+
devicePath: string;
|
|
39
|
+
inputReportLength: number;
|
|
40
|
+
outputReportLength: number;
|
|
41
|
+
featureReportLength: number;
|
|
42
|
+
isOpen: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface ConnectionConfig {
|
|
45
|
+
url: string;
|
|
46
|
+
protocols?: string[];
|
|
47
|
+
reconnectInterval?: number;
|
|
48
|
+
maxReconnectAttempts?: number;
|
|
49
|
+
timeout?: number;
|
|
50
|
+
}
|
|
51
|
+
interface JsonRpcRequest {
|
|
52
|
+
jsonrpc: '2.0';
|
|
53
|
+
method: string;
|
|
54
|
+
params?: any;
|
|
55
|
+
id?: string | number | null;
|
|
56
|
+
}
|
|
57
|
+
interface JsonRpcResponse {
|
|
58
|
+
jsonrpc: '2.0';
|
|
59
|
+
result?: any;
|
|
60
|
+
error?: JsonRpcError;
|
|
61
|
+
id?: string | number | null;
|
|
62
|
+
}
|
|
63
|
+
interface JsonRpcError {
|
|
64
|
+
code: number;
|
|
65
|
+
message: string;
|
|
66
|
+
data?: any;
|
|
67
|
+
}
|
|
68
|
+
interface PrintJob {
|
|
69
|
+
id: string;
|
|
70
|
+
deviceId: string;
|
|
71
|
+
data: string;
|
|
72
|
+
format: 'raw' | 'escpos' | 'zpl' | 'epl';
|
|
73
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
startedAt?: Date;
|
|
76
|
+
completedAt?: Date;
|
|
77
|
+
error?: string;
|
|
78
|
+
retryCount: number;
|
|
79
|
+
options?: Record<string, any>;
|
|
80
|
+
}
|
|
81
|
+
interface PrintResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
jobId?: string;
|
|
84
|
+
bytesPrinted?: number;
|
|
85
|
+
error?: string;
|
|
86
|
+
timestamp: Date;
|
|
87
|
+
}
|
|
88
|
+
interface SerialPortConfig {
|
|
89
|
+
baudRate: number;
|
|
90
|
+
parity: 'None' | 'Odd' | 'Even' | 'Mark' | 'Space';
|
|
91
|
+
dataBits: 7 | 8;
|
|
92
|
+
stopBits: '1' | '1.5' | '2';
|
|
93
|
+
flowControl: 'None' | 'XOnXOff' | 'RequestToSend' | 'RequestToSendXOnXOff';
|
|
94
|
+
}
|
|
95
|
+
interface SerialData {
|
|
96
|
+
deviceId: string;
|
|
97
|
+
data: string;
|
|
98
|
+
timestamp: Date;
|
|
99
|
+
direction: 'send' | 'receive';
|
|
100
|
+
bytesTransferred: number;
|
|
101
|
+
}
|
|
102
|
+
interface UsbHidReport {
|
|
103
|
+
deviceId: string;
|
|
104
|
+
reportId: number;
|
|
105
|
+
data: string;
|
|
106
|
+
timestamp: Date;
|
|
107
|
+
reportType: 'input' | 'output' | 'feature';
|
|
108
|
+
}
|
|
109
|
+
interface QueueJob {
|
|
110
|
+
id: string;
|
|
111
|
+
deviceId: string;
|
|
112
|
+
deviceType: string;
|
|
113
|
+
operation: string;
|
|
114
|
+
status: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
115
|
+
createdAt: Date;
|
|
116
|
+
startedAt?: Date;
|
|
117
|
+
completedAt?: Date;
|
|
118
|
+
error?: string;
|
|
119
|
+
retryCount: number;
|
|
120
|
+
parameters?: Record<string, any>;
|
|
121
|
+
}
|
|
122
|
+
interface QueueStatus {
|
|
123
|
+
totalJobs: number;
|
|
124
|
+
pendingJobs: number;
|
|
125
|
+
processingJobs: number;
|
|
126
|
+
completedJobs: number;
|
|
127
|
+
failedJobs: number;
|
|
128
|
+
lastProcessed: Date;
|
|
129
|
+
averageProcessingTime: number;
|
|
130
|
+
}
|
|
131
|
+
interface SystemHealth {
|
|
132
|
+
status: 'healthy' | 'warning' | 'error' | 'no_devices';
|
|
133
|
+
timestamp: Date;
|
|
134
|
+
totalDevices: number;
|
|
135
|
+
connectedDevices: number;
|
|
136
|
+
activeConnections: number;
|
|
137
|
+
jobsInQueue: number;
|
|
138
|
+
cpuUsage: number;
|
|
139
|
+
memoryUsage: number;
|
|
140
|
+
deviceHealth: Record<string, any>;
|
|
141
|
+
}
|
|
142
|
+
interface ConnectionState {
|
|
143
|
+
connected: boolean;
|
|
144
|
+
connecting: boolean;
|
|
145
|
+
error?: string;
|
|
146
|
+
reconnectAttempts: number;
|
|
147
|
+
lastConnectionTime?: Date;
|
|
148
|
+
}
|
|
149
|
+
interface DeviceEvent {
|
|
150
|
+
eventType: 'connected' | 'disconnected' | 'discovered' | 'removed' | 'status_changed' | 'error' | 'data';
|
|
151
|
+
deviceId: string;
|
|
152
|
+
deviceType: string;
|
|
153
|
+
timestamp: Date;
|
|
154
|
+
data?: Record<string, any>;
|
|
155
|
+
}
|
|
156
|
+
interface ClientOptions {
|
|
157
|
+
autoReconnect?: boolean;
|
|
158
|
+
reconnectInterval?: number;
|
|
159
|
+
maxReconnectAttempts?: number;
|
|
160
|
+
timeout?: number;
|
|
161
|
+
debug?: boolean;
|
|
162
|
+
protocols?: string[];
|
|
163
|
+
headers?: Record<string, string>;
|
|
164
|
+
}
|
|
165
|
+
type DeviceType = 'printer' | 'serial' | 'usbhid';
|
|
166
|
+
type PrintFormat = 'raw' | 'escpos' | 'zpl' | 'epl';
|
|
167
|
+
type JobStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
168
|
+
type ConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error' | 'reconnecting';
|
|
169
|
+
|
|
170
|
+
declare class HardwareBridgeClient {
|
|
171
|
+
private wsClient;
|
|
172
|
+
private options;
|
|
173
|
+
constructor(config: ConnectionConfig, options?: ClientOptions);
|
|
174
|
+
private setupEventHandlers;
|
|
175
|
+
connect(): Promise<void>;
|
|
176
|
+
disconnect(): void;
|
|
177
|
+
get isConnected(): boolean;
|
|
178
|
+
get isConnecting(): boolean;
|
|
179
|
+
getConnectionStatus(): string;
|
|
180
|
+
onConnectionStateChange(listener: (connected: boolean) => void): void;
|
|
181
|
+
enumerateDevices(): Promise<DeviceInfo[]>;
|
|
182
|
+
getDevice(deviceId: string): Promise<DeviceInfo>;
|
|
183
|
+
watchDevices(): Promise<void>;
|
|
184
|
+
unwatchDevices(): Promise<void>;
|
|
185
|
+
print(deviceId: string, data: string, format?: PrintFormat): Promise<PrintResult>;
|
|
186
|
+
getPrinterStatus(deviceId: string): Promise<{
|
|
187
|
+
isConnected: boolean;
|
|
188
|
+
status: string;
|
|
189
|
+
isReady: boolean;
|
|
190
|
+
isBusy: boolean;
|
|
191
|
+
isPaused: boolean;
|
|
192
|
+
jobsInQueue: number;
|
|
193
|
+
error?: string;
|
|
194
|
+
timestamp: Date;
|
|
195
|
+
}>;
|
|
196
|
+
getPrinterCapabilities(deviceId: string): Promise<{
|
|
197
|
+
supportedProtocols: string[];
|
|
198
|
+
maxPrintWidth: number;
|
|
199
|
+
supportsColor: boolean;
|
|
200
|
+
supportsDuplex: boolean;
|
|
201
|
+
maxResolution: number;
|
|
202
|
+
maxJobSize: number;
|
|
203
|
+
error?: string;
|
|
204
|
+
}>;
|
|
205
|
+
openSerialPort(deviceId: string, config: SerialPortConfig): Promise<{
|
|
206
|
+
success: boolean;
|
|
207
|
+
portName?: string;
|
|
208
|
+
config?: SerialPortConfig;
|
|
209
|
+
openedAt?: Date;
|
|
210
|
+
error?: string;
|
|
211
|
+
}>;
|
|
212
|
+
closeSerialPort(deviceId: string): Promise<{
|
|
213
|
+
success: boolean;
|
|
214
|
+
portName?: string;
|
|
215
|
+
closedAt?: Date;
|
|
216
|
+
error?: string;
|
|
217
|
+
}>;
|
|
218
|
+
sendSerialData(deviceId: string, data: string): Promise<{
|
|
219
|
+
success: boolean;
|
|
220
|
+
bytesTransferred: number;
|
|
221
|
+
data: string;
|
|
222
|
+
error?: string;
|
|
223
|
+
timestamp: Date;
|
|
224
|
+
}>;
|
|
225
|
+
receiveSerialData(deviceId: string, maxBytes?: number, timeout?: number): Promise<{
|
|
226
|
+
success: boolean;
|
|
227
|
+
bytesTransferred: number;
|
|
228
|
+
data: string;
|
|
229
|
+
error?: string;
|
|
230
|
+
timestamp: Date;
|
|
231
|
+
}>;
|
|
232
|
+
getSerialPortStatus(deviceId: string): Promise<{
|
|
233
|
+
isConnected: boolean;
|
|
234
|
+
status: string;
|
|
235
|
+
portName?: string;
|
|
236
|
+
baudRate?: number;
|
|
237
|
+
parity?: string;
|
|
238
|
+
dataBits?: number;
|
|
239
|
+
stopBits?: string;
|
|
240
|
+
flowControl?: string;
|
|
241
|
+
bytesToRead?: number;
|
|
242
|
+
bytesToWrite?: number;
|
|
243
|
+
isOpen?: boolean;
|
|
244
|
+
cdHolding?: boolean;
|
|
245
|
+
ctsHolding?: boolean;
|
|
246
|
+
dsrHolding?: boolean;
|
|
247
|
+
connectedAt?: Date;
|
|
248
|
+
lastActivity?: Date;
|
|
249
|
+
error?: string;
|
|
250
|
+
}>;
|
|
251
|
+
openUsbDevice(deviceId: string): Promise<{
|
|
252
|
+
success: boolean;
|
|
253
|
+
deviceId: string;
|
|
254
|
+
vendorId?: number;
|
|
255
|
+
productId?: number;
|
|
256
|
+
openedAt?: Date;
|
|
257
|
+
error?: string;
|
|
258
|
+
}>;
|
|
259
|
+
closeUsbDevice(deviceId: string): Promise<{
|
|
260
|
+
success: boolean;
|
|
261
|
+
deviceId: string;
|
|
262
|
+
closedAt?: Date;
|
|
263
|
+
error?: string;
|
|
264
|
+
}>;
|
|
265
|
+
sendUsbReport(deviceId: string, reportId: number, data: string): Promise<{
|
|
266
|
+
success: boolean;
|
|
267
|
+
reportId: number;
|
|
268
|
+
bytesTransferred: number;
|
|
269
|
+
data: string;
|
|
270
|
+
error?: string;
|
|
271
|
+
timestamp: Date;
|
|
272
|
+
}>;
|
|
273
|
+
receiveUsbReport(deviceId: string, reportId: number, timeout?: number): Promise<{
|
|
274
|
+
success: boolean;
|
|
275
|
+
reportId: number;
|
|
276
|
+
bytesTransferred: number;
|
|
277
|
+
data: string;
|
|
278
|
+
error?: string;
|
|
279
|
+
timestamp: Date;
|
|
280
|
+
}>;
|
|
281
|
+
getUsbDeviceStatus(deviceId: string): Promise<{
|
|
282
|
+
isConnected: boolean;
|
|
283
|
+
status: string;
|
|
284
|
+
deviceId: string;
|
|
285
|
+
vendorId?: number;
|
|
286
|
+
productId?: number;
|
|
287
|
+
version?: number;
|
|
288
|
+
isOpen?: boolean;
|
|
289
|
+
inputReportLength?: number;
|
|
290
|
+
outputReportLength?: number;
|
|
291
|
+
featureReportLength?: number;
|
|
292
|
+
connectedAt?: Date;
|
|
293
|
+
lastActivity?: Date;
|
|
294
|
+
error?: string;
|
|
295
|
+
}>;
|
|
296
|
+
getQueueStatus(): Promise<QueueStatus>;
|
|
297
|
+
getQueueJobs(deviceId?: string, status?: string, limit?: number): Promise<QueueJob[]>;
|
|
298
|
+
cancelQueueJob(jobId: string): Promise<boolean>;
|
|
299
|
+
getSystemInfo(): Promise<{
|
|
300
|
+
version: string;
|
|
301
|
+
platform: string;
|
|
302
|
+
timestamp: Date;
|
|
303
|
+
uptime: number;
|
|
304
|
+
}>;
|
|
305
|
+
getSystemHealth(): Promise<SystemHealth>;
|
|
306
|
+
onDeviceEvent(event: DeviceEvent): void;
|
|
307
|
+
waitForConnection(timeout?: number): Promise<void>;
|
|
308
|
+
dispose(): void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
declare class WebSocketClient {
|
|
312
|
+
private ws;
|
|
313
|
+
private config;
|
|
314
|
+
private options;
|
|
315
|
+
private connectionState;
|
|
316
|
+
private connectionListeners;
|
|
317
|
+
private messageListeners;
|
|
318
|
+
private deviceEventListeners;
|
|
319
|
+
private reconnectTimer;
|
|
320
|
+
private pingTimer;
|
|
321
|
+
private messageId;
|
|
322
|
+
private pendingRequests;
|
|
323
|
+
constructor(config: ConnectionConfig, options?: ClientOptions);
|
|
324
|
+
onConnectionStateChange(listener: (state: ConnectionState) => void): void;
|
|
325
|
+
onMessage(listener: (message: JsonRpcResponse) => void): void;
|
|
326
|
+
onDeviceEvent(listener: (event: DeviceEvent) => void): void;
|
|
327
|
+
get isConnected(): boolean;
|
|
328
|
+
get isConnecting(): boolean;
|
|
329
|
+
getConnectionStatus(): ConnectionStatus;
|
|
330
|
+
connect(): Promise<void>;
|
|
331
|
+
disconnect(): void;
|
|
332
|
+
sendRequest<T = any>(method: string, params?: any): Promise<T>;
|
|
333
|
+
sendNotification(method: string, params?: any): void;
|
|
334
|
+
private createWebSocket;
|
|
335
|
+
private handleMessage;
|
|
336
|
+
private handleDisconnect;
|
|
337
|
+
private scheduleReconnect;
|
|
338
|
+
private startPingTimer;
|
|
339
|
+
private cleanup;
|
|
340
|
+
private sendMessage;
|
|
341
|
+
private updateConnectionState;
|
|
342
|
+
private log;
|
|
343
|
+
dispose(): void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
declare const VERSION = "1.0.0";
|
|
347
|
+
|
|
348
|
+
export { HardwareBridgeClient, VERSION, WebSocketClient };
|
|
349
|
+
export type { ClientOptions, ConnectionConfig, ConnectionState, ConnectionStatus, ConnectionStatus as ConnectionStatusType, DeviceEvent, DeviceInfo, DeviceType, JobStatus, JsonRpcError, JsonRpcRequest, JsonRpcResponse, PrintFormat, PrintJob, PrintResult, PrinterDevice, QueueJob, QueueStatus, SerialData, SerialPortConfig, SerialPortDevice, SystemHealth, UsbHidDevice, UsbHidReport };
|