@rdlabo/capacitor-brotherprint 8.2.0 → 8.2.1
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/README.md +7 -0
- package/dist/esm/index.d.ts +49 -0
- package/dist/esm/index.js +184 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models.d.ts +2 -0
- package/dist/esm/models.js +10 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/printer.d.ts +9 -0
- package/dist/esm/printer.js +46 -0
- package/dist/esm/printer.js.map +1 -0
- package/dist/plugin.cjs.js +274 -34
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +274 -34
- package/dist/plugin.js.map +1 -1
- package/docs/connection-management.md +151 -0
- package/docs/helper-design.md +42 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -50,6 +50,13 @@ Amazon Affiliate Links: **https://amzn.to/3AiiOFT**
|
|
|
50
50
|
|
|
51
51
|
※1 Due to low Bluetooth version, connection is not possible with iOS. Ref: https://okbizcs.okwave.jp/brother/qa/q9932082.html
|
|
52
52
|
|
|
53
|
+
## JavaScript helpers
|
|
54
|
+
|
|
55
|
+
`BrotherPrinterSession` owns a print screen's discovery results, print listeners and
|
|
56
|
+
shutdown. Pure functions provide model/connection choices, and stateless connection
|
|
57
|
+
helpers remain available. None require Angular or Ionic. See
|
|
58
|
+
[connection management](docs/connection-management.md) for usage.
|
|
59
|
+
|
|
53
60
|
## API
|
|
54
61
|
|
|
55
62
|
<docgen-index>
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { BRLMPrinterModelName } from './brother-printer.enum';
|
|
1
2
|
import type { BrotherPrintPlugin } from './definitions';
|
|
3
|
+
import type { BRLMChannelResult, BRLMPrintOptions, BRLMSearchOption, ErrorInfo } from './interfaces';
|
|
2
4
|
declare const BrotherPrint: BrotherPrintPlugin;
|
|
3
5
|
export * from './definitions';
|
|
4
6
|
export * from './web';
|
|
@@ -6,3 +8,50 @@ export * from './events.enum';
|
|
|
6
8
|
export * from './interfaces';
|
|
7
9
|
export * from './brother-printer.enum';
|
|
8
10
|
export { BrotherPrint };
|
|
11
|
+
export * from './printer';
|
|
12
|
+
/** Collect discovery results, waiting for earlier helper calls to finish. */
|
|
13
|
+
export declare function searchBrotherPrinters(options: BRLMSearchOption, model?: BRLMPrinterModelName): Promise<BRLMChannelResult[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Reuse a matching, available previous channel; otherwise discover printers.
|
|
16
|
+
* The caller owns storage. USB always discovers again through the native permission flow.
|
|
17
|
+
* Availability errors propagate; only an unavailable channel triggers discovery.
|
|
18
|
+
*/
|
|
19
|
+
export declare function prepareBrotherPrinters(options: BRLMSearchOption, model: BRLMPrinterModelName, previous?: BRLMChannelResult | null): Promise<BRLMChannelResult[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Check an explicitly selected address without discovery or fallback to another printer.
|
|
22
|
+
* Port must be supplied; an address does not identify its transport or printer model.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkBrotherPrinterChannel(channel: Pick<BRLMChannelResult, 'port' | 'channelInfo'>): Promise<boolean>;
|
|
25
|
+
export interface BrotherPrinterEvents {
|
|
26
|
+
onPrint?: () => void;
|
|
27
|
+
onPrintError?: (info: ErrorInfo) => void;
|
|
28
|
+
onPrintFailedCommunication?: (info: ErrorInfo) => void;
|
|
29
|
+
}
|
|
30
|
+
/** String storage callbacks; both synchronous and asynchronous stores are supported. */
|
|
31
|
+
export interface BrotherPrinterStorage {
|
|
32
|
+
get(key: string): string | null | undefined | Promise<string | null | undefined>;
|
|
33
|
+
set(key: string, value: string): unknown;
|
|
34
|
+
remove(key: string): unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface BrotherPrinterSessionOptions {
|
|
37
|
+
storage?: BrotherPrinterStorage;
|
|
38
|
+
/** Defaults to `brotherprint:`. The session appends `last-printer`. */
|
|
39
|
+
storagePrefix?: string;
|
|
40
|
+
}
|
|
41
|
+
/** One print screen's discovery results and event subscriptions. Create a new session after disposal. */
|
|
42
|
+
export declare class BrotherPrinterSession {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(options?: BrotherPrinterSessionOptions);
|
|
45
|
+
get closed(): boolean;
|
|
46
|
+
get printers(): readonly BRLMChannelResult[];
|
|
47
|
+
search(options: BRLMSearchOption, model?: BRLMPrinterModelName): Promise<readonly BRLMChannelResult[]>;
|
|
48
|
+
prepare(options: BRLMSearchOption, model: BRLMPrinterModelName, previous?: BRLMChannelResult | null): Promise<readonly BRLMChannelResult[]>;
|
|
49
|
+
/** Forget the remembered connection. Storage removal errors propagate to the caller. */
|
|
50
|
+
clearSavedPrinter(): Promise<void>;
|
|
51
|
+
/** Register print notifications once. Callbacks stop immediately when disposed. */
|
|
52
|
+
listen(events: BrotherPrinterEvents): Promise<void>;
|
|
53
|
+
/** A closed session cannot start another print. Already started native printing is awaited. */
|
|
54
|
+
printImage(options: BRLMPrintOptions): Promise<void>;
|
|
55
|
+
/** Invalidate pending work immediately, then remove this session's print listeners. */
|
|
56
|
+
dispose(): Promise<void>;
|
|
57
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _BrotherPrinterSession_instances, _BrotherPrinterSession_closed, _BrotherPrinterSession_printers, _BrotherPrinterSession_listeners, _BrotherPrinterSession_listening, _BrotherPrinterSession_disposal, _BrotherPrinterSession_storage, _BrotherPrinterSession_storageKey, _BrotherPrinterSession_readSavedPrinter, _BrotherPrinterSession_savePrinter, _BrotherPrinterSession_discover;
|
|
1
13
|
import { registerPlugin } from '@capacitor/core';
|
|
14
|
+
import { BRLMPrinterPort } from './brother-printer.enum';
|
|
15
|
+
import { BrotherPrintEventsEnum } from './events.enum';
|
|
16
|
+
import { brotherPrinterModel } from './printer';
|
|
2
17
|
const BrotherPrint = registerPlugin('BrotherPrint', {
|
|
3
18
|
web: () => import('./web').then((m) => new m.BrotherPrintWeb()),
|
|
4
19
|
});
|
|
@@ -8,4 +23,173 @@ export * from './events.enum';
|
|
|
8
23
|
export * from './interfaces';
|
|
9
24
|
export * from './brother-printer.enum';
|
|
10
25
|
export { BrotherPrint };
|
|
26
|
+
export * from './printer';
|
|
27
|
+
// Native discovery events are shared. Keep each helper call's listener scoped to its turn.
|
|
28
|
+
let connectionQueue = Promise.resolve();
|
|
29
|
+
function queueConnection(run) {
|
|
30
|
+
const result = connectionQueue.then(run);
|
|
31
|
+
connectionQueue = result.catch(() => undefined);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/** Collect discovery results, waiting for earlier helper calls to finish. */
|
|
35
|
+
export function searchBrotherPrinters(options, model) {
|
|
36
|
+
return queueConnection(() => discoverPrinters(options, model));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reuse a matching, available previous channel; otherwise discover printers.
|
|
40
|
+
* The caller owns storage. USB always discovers again through the native permission flow.
|
|
41
|
+
* Availability errors propagate; only an unavailable channel triggers discovery.
|
|
42
|
+
*/
|
|
43
|
+
export function prepareBrotherPrinters(options, model, previous) {
|
|
44
|
+
return queueConnection(() => preparePrinters(options, model, previous));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check an explicitly selected address without discovery or fallback to another printer.
|
|
48
|
+
* Port must be supplied; an address does not identify its transport or printer model.
|
|
49
|
+
*/
|
|
50
|
+
export function checkBrotherPrinterChannel(channel) {
|
|
51
|
+
return queueConnection(async () => {
|
|
52
|
+
const { result } = await BrotherPrint.isChannelAvailable(Object.assign({ modelName: '', serialNumber: '', macAddress: '', nodeName: '', location: '' }, channel));
|
|
53
|
+
return result;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function discoverPrinters(options, model, active = () => true) {
|
|
57
|
+
const printers = [];
|
|
58
|
+
const listener = await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrinterAvailable, (printer) => {
|
|
59
|
+
if (printer.port !== options.port)
|
|
60
|
+
return;
|
|
61
|
+
if (printer.port !== BRLMPrinterPort.usb && model !== undefined && brotherPrinterModel(printer.modelName) !== model)
|
|
62
|
+
return;
|
|
63
|
+
const index = printers.findIndex((current) => current.port === printer.port && current.channelInfo === printer.channelInfo);
|
|
64
|
+
if (index < 0)
|
|
65
|
+
printers.push(printer);
|
|
66
|
+
else
|
|
67
|
+
printers[index] = printer;
|
|
68
|
+
});
|
|
69
|
+
await (active() ? BrotherPrint.search(options) : Promise.resolve()).finally(() => listener.remove());
|
|
70
|
+
return printers;
|
|
71
|
+
}
|
|
72
|
+
async function preparePrinters(options, model, previous, active = () => true) {
|
|
73
|
+
if (options.port !== BRLMPrinterPort.usb &&
|
|
74
|
+
(previous === null || previous === void 0 ? void 0 : previous.port) === options.port &&
|
|
75
|
+
previous.channelInfo.trim() &&
|
|
76
|
+
brotherPrinterModel(previous.modelName) === model) {
|
|
77
|
+
const available = await BrotherPrint.isChannelAvailable(previous);
|
|
78
|
+
if (available.result)
|
|
79
|
+
return [previous];
|
|
80
|
+
}
|
|
81
|
+
return active() ? discoverPrinters(options, model, active) : [];
|
|
82
|
+
}
|
|
83
|
+
/** One print screen's discovery results and event subscriptions. Create a new session after disposal. */
|
|
84
|
+
export class BrotherPrinterSession {
|
|
85
|
+
constructor(options = {}) {
|
|
86
|
+
var _a;
|
|
87
|
+
_BrotherPrinterSession_instances.add(this);
|
|
88
|
+
_BrotherPrinterSession_closed.set(this, false);
|
|
89
|
+
_BrotherPrinterSession_printers.set(this, []);
|
|
90
|
+
_BrotherPrinterSession_listeners.set(this, []);
|
|
91
|
+
_BrotherPrinterSession_listening.set(this, void 0);
|
|
92
|
+
_BrotherPrinterSession_disposal.set(this, void 0);
|
|
93
|
+
_BrotherPrinterSession_storage.set(this, void 0);
|
|
94
|
+
_BrotherPrinterSession_storageKey.set(this, void 0);
|
|
95
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_storage, options.storage, "f");
|
|
96
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_storageKey, `${(_a = options.storagePrefix) !== null && _a !== void 0 ? _a : 'brotherprint:'}last-printer`, "f");
|
|
97
|
+
}
|
|
98
|
+
get closed() {
|
|
99
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f");
|
|
100
|
+
}
|
|
101
|
+
get printers() {
|
|
102
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_printers, "f");
|
|
103
|
+
}
|
|
104
|
+
search(options, model) {
|
|
105
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_instances, "m", _BrotherPrinterSession_discover).call(this, () => discoverPrinters(options, model, () => !__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f")));
|
|
106
|
+
}
|
|
107
|
+
prepare(options, model, previous) {
|
|
108
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_instances, "m", _BrotherPrinterSession_discover).call(this, async () => {
|
|
109
|
+
const saved = previous === undefined ? await __classPrivateFieldGet(this, _BrotherPrinterSession_instances, "m", _BrotherPrinterSession_readSavedPrinter).call(this).catch(() => undefined) : previous;
|
|
110
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
111
|
+
return [];
|
|
112
|
+
return preparePrinters(options, model, saved, () => !__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Forget the remembered connection. Storage removal errors propagate to the caller. */
|
|
116
|
+
async clearSavedPrinter() {
|
|
117
|
+
var _a;
|
|
118
|
+
await ((_a = __classPrivateFieldGet(this, _BrotherPrinterSession_storage, "f")) === null || _a === void 0 ? void 0 : _a.remove(__classPrivateFieldGet(this, _BrotherPrinterSession_storageKey, "f")));
|
|
119
|
+
}
|
|
120
|
+
/** Register print notifications once. Callbacks stop immediately when disposed. */
|
|
121
|
+
listen(events) {
|
|
122
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
123
|
+
return Promise.resolve();
|
|
124
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_listening, "f")) {
|
|
125
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_listeners, [
|
|
126
|
+
BrotherPrint.addListener(BrotherPrintEventsEnum.onPrint, () => {
|
|
127
|
+
var _a;
|
|
128
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
129
|
+
(_a = events.onPrint) === null || _a === void 0 ? void 0 : _a.call(events);
|
|
130
|
+
}),
|
|
131
|
+
BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintError, (info) => {
|
|
132
|
+
var _a;
|
|
133
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
134
|
+
(_a = events.onPrintError) === null || _a === void 0 ? void 0 : _a.call(events, info);
|
|
135
|
+
}),
|
|
136
|
+
BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintFailedCommunication, (info) => {
|
|
137
|
+
var _a;
|
|
138
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
139
|
+
(_a = events.onPrintFailedCommunication) === null || _a === void 0 ? void 0 : _a.call(events, info);
|
|
140
|
+
}),
|
|
141
|
+
], "f");
|
|
142
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_listening, Promise.all(__classPrivateFieldGet(this, _BrotherPrinterSession_listeners, "f")).then(() => undefined), "f");
|
|
143
|
+
}
|
|
144
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_listening, "f");
|
|
145
|
+
}
|
|
146
|
+
/** A closed session cannot start another print. Already started native printing is awaited. */
|
|
147
|
+
async printImage(options) {
|
|
148
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
149
|
+
return;
|
|
150
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_storage, "f"))
|
|
151
|
+
await __classPrivateFieldGet(this, _BrotherPrinterSession_instances, "m", _BrotherPrinterSession_savePrinter).call(this, options).catch(() => undefined);
|
|
152
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
153
|
+
await BrotherPrint.printImage(options);
|
|
154
|
+
}
|
|
155
|
+
/** Invalidate pending work immediately, then remove this session's print listeners. */
|
|
156
|
+
dispose() {
|
|
157
|
+
var _a;
|
|
158
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_closed, true, "f");
|
|
159
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_printers, [], "f");
|
|
160
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_disposal, (_a = __classPrivateFieldGet(this, _BrotherPrinterSession_disposal, "f")) !== null && _a !== void 0 ? _a : Promise.all(__classPrivateFieldGet(this, _BrotherPrinterSession_listeners, "f").map((listener) => listener.then((handle) => handle.remove()))).then(() => undefined), "f");
|
|
161
|
+
return __classPrivateFieldGet(this, _BrotherPrinterSession_disposal, "f");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_BrotherPrinterSession_closed = new WeakMap(), _BrotherPrinterSession_printers = new WeakMap(), _BrotherPrinterSession_listeners = new WeakMap(), _BrotherPrinterSession_listening = new WeakMap(), _BrotherPrinterSession_disposal = new WeakMap(), _BrotherPrinterSession_storage = new WeakMap(), _BrotherPrinterSession_storageKey = new WeakMap(), _BrotherPrinterSession_instances = new WeakSet(), _BrotherPrinterSession_readSavedPrinter = async function _BrotherPrinterSession_readSavedPrinter() {
|
|
165
|
+
var _a;
|
|
166
|
+
const value = await ((_a = __classPrivateFieldGet(this, _BrotherPrinterSession_storage, "f")) === null || _a === void 0 ? void 0 : _a.get(__classPrivateFieldGet(this, _BrotherPrinterSession_storageKey, "f")));
|
|
167
|
+
if (!value)
|
|
168
|
+
return undefined;
|
|
169
|
+
const channel = JSON.parse(value);
|
|
170
|
+
if (channel &&
|
|
171
|
+
Object.values(BRLMPrinterPort).includes(channel.port) &&
|
|
172
|
+
['modelName', 'channelInfo', 'serialNumber', 'macAddress', 'nodeName', 'location'].every((key) => typeof channel[key] === 'string'))
|
|
173
|
+
return channel;
|
|
174
|
+
return undefined;
|
|
175
|
+
}, _BrotherPrinterSession_savePrinter = async function _BrotherPrinterSession_savePrinter(options) {
|
|
176
|
+
var _a;
|
|
177
|
+
if (!__classPrivateFieldGet(this, _BrotherPrinterSession_storage, "f") || !options.port || !((_a = options.channelInfo) === null || _a === void 0 ? void 0 : _a.trim()))
|
|
178
|
+
return;
|
|
179
|
+
const found = __classPrivateFieldGet(this, _BrotherPrinterSession_printers, "f").find((printer) => printer.port === options.port && printer.channelInfo === options.channelInfo);
|
|
180
|
+
const channel = Object.assign(Object.assign({ serialNumber: '', macAddress: '', nodeName: '', location: '' }, found), { port: options.port, channelInfo: options.channelInfo, modelName: options.modelName });
|
|
181
|
+
await __classPrivateFieldGet(this, _BrotherPrinterSession_storage, "f").set(__classPrivateFieldGet(this, _BrotherPrinterSession_storageKey, "f"), JSON.stringify(channel));
|
|
182
|
+
}, _BrotherPrinterSession_discover = function _BrotherPrinterSession_discover(run) {
|
|
183
|
+
return queueConnection(async () => {
|
|
184
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
185
|
+
return [];
|
|
186
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_printers, [], "f");
|
|
187
|
+
return run().then((printers) => {
|
|
188
|
+
if (__classPrivateFieldGet(this, _BrotherPrinterSession_closed, "f"))
|
|
189
|
+
return [];
|
|
190
|
+
__classPrivateFieldSet(this, _BrotherPrinterSession_printers, printers, "f");
|
|
191
|
+
return printers;
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
11
195
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { BrotherPrintPlugin } from './definitions';\n\nconst BrotherPrint = registerPlugin<BrotherPrintPlugin>('BrotherPrint', {\n web: () => import('./web').then((m) => new m.BrotherPrintWeb()),\n});\n\nexport * from './definitions';\nexport * from './web';\nexport * from './events.enum';\nexport * from './interfaces';\nexport * from './brother-printer.enum';\nexport { BrotherPrint };\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mapp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IAAI,IAAI,OAAO,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,CAC1F,CAAC;IACF,MAAM,OAAO,iCACX,YAAY,EAAE,EAAE,EAChB,UAAU,EAAE,EAAE,EACd,QAAQ,EAAE,EAAE,EACZ,QAAQ,EAAE,EAAE,IACT,KAAK,KACR,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,SAAS,EAAE,OAAO,CAAC,SAAS,GAC7B,CAAC;IACF,MAAM,uBAAA,IAAI,sCAAS,CAAC,GAAG,CAAC,uBAAA,IAAI,yCAAY,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC,6EAES,GAAuC;IAC/C,OAAO,eAAe,CAAC,KAAK,IAAI,EAAE;QAChC,IAAI,uBAAA,IAAI,qCAAQ;YAAE,OAAO,EAAE,CAAC;QAC5B,uBAAA,IAAI,mCAAa,EAAE,MAAA,CAAC;QACpB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,IAAI,uBAAA,IAAI,qCAAQ;gBAAE,OAAO,EAAE,CAAC;YAC5B,uBAAA,IAAI,mCAAa,QAAQ,MAAA,CAAC;YAC1B,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { registerPlugin } from '@capacitor/core';\n\nimport type { BRLMPrinterModelName } from './brother-printer.enum';\nimport { BRLMPrinterPort } from './brother-printer.enum';\nimport type { BrotherPrintPlugin } from './definitions';\nimport { BrotherPrintEventsEnum } from './events.enum';\nimport type { BRLMChannelResult, BRLMPrintOptions, BRLMSearchOption, ErrorInfo } from './interfaces';\nimport { brotherPrinterModel } from './printer';\n\nconst BrotherPrint = registerPlugin<BrotherPrintPlugin>('BrotherPrint', {\n web: () => import('./web').then((m) => new m.BrotherPrintWeb()),\n});\n\nexport * from './definitions';\nexport * from './web';\nexport * from './events.enum';\nexport * from './interfaces';\nexport * from './brother-printer.enum';\nexport { BrotherPrint };\n\nexport * from './printer';\n\n// Native discovery events are shared. Keep each helper call's listener scoped to its turn.\nlet connectionQueue: Promise<unknown> = Promise.resolve();\n\nfunction queueConnection<T>(run: () => Promise<T>): Promise<T> {\n const result = connectionQueue.then(run);\n connectionQueue = result.catch(() => undefined);\n return result;\n}\n\n/** Collect discovery results, waiting for earlier helper calls to finish. */\nexport function searchBrotherPrinters(\n options: BRLMSearchOption,\n model?: BRLMPrinterModelName,\n): Promise<BRLMChannelResult[]> {\n return queueConnection(() => discoverPrinters(options, model));\n}\n\n/**\n * Reuse a matching, available previous channel; otherwise discover printers.\n * The caller owns storage. USB always discovers again through the native permission flow.\n * Availability errors propagate; only an unavailable channel triggers discovery.\n */\nexport function prepareBrotherPrinters(\n options: BRLMSearchOption,\n model: BRLMPrinterModelName,\n previous?: BRLMChannelResult | null,\n): Promise<BRLMChannelResult[]> {\n return queueConnection(() => preparePrinters(options, model, previous));\n}\n\n/**\n * Check an explicitly selected address without discovery or fallback to another printer.\n * Port must be supplied; an address does not identify its transport or printer model.\n */\nexport function checkBrotherPrinterChannel(channel: Pick<BRLMChannelResult, 'port' | 'channelInfo'>): Promise<boolean> {\n return queueConnection(async () => {\n const { result } = await BrotherPrint.isChannelAvailable({\n modelName: '',\n serialNumber: '',\n macAddress: '',\n nodeName: '',\n location: '',\n ...channel,\n });\n return result;\n });\n}\n\nasync function discoverPrinters(\n options: BRLMSearchOption,\n model?: BRLMPrinterModelName,\n active: () => boolean = () => true,\n): Promise<BRLMChannelResult[]> {\n const printers: BRLMChannelResult[] = [];\n const listener = await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrinterAvailable, (printer) => {\n if (printer.port !== options.port) return;\n if (printer.port !== BRLMPrinterPort.usb && model !== undefined && brotherPrinterModel(printer.modelName) !== model)\n return;\n const index = printers.findIndex(\n (current) => current.port === printer.port && current.channelInfo === printer.channelInfo,\n );\n if (index < 0) printers.push(printer);\n else printers[index] = printer;\n });\n await (active() ? BrotherPrint.search(options) : Promise.resolve()).finally(() => listener.remove());\n return printers;\n}\n\nasync function preparePrinters(\n options: BRLMSearchOption,\n model: BRLMPrinterModelName,\n previous?: BRLMChannelResult | null,\n active: () => boolean = () => true,\n): Promise<BRLMChannelResult[]> {\n if (\n options.port !== BRLMPrinterPort.usb &&\n previous?.port === options.port &&\n previous.channelInfo.trim() &&\n brotherPrinterModel(previous.modelName) === model\n ) {\n const available = await BrotherPrint.isChannelAvailable(previous);\n if (available.result) return [previous];\n }\n return active() ? discoverPrinters(options, model, active) : [];\n}\n\nexport interface BrotherPrinterEvents {\n onPrint?: () => void;\n onPrintError?: (info: ErrorInfo) => void;\n onPrintFailedCommunication?: (info: ErrorInfo) => void;\n}\n\n/** String storage callbacks; both synchronous and asynchronous stores are supported. */\nexport interface BrotherPrinterStorage {\n get(key: string): string | null | undefined | Promise<string | null | undefined>;\n set(key: string, value: string): unknown;\n remove(key: string): unknown;\n}\n\nexport interface BrotherPrinterSessionOptions {\n storage?: BrotherPrinterStorage;\n /** Defaults to `brotherprint:`. The session appends `last-printer`. */\n storagePrefix?: string;\n}\n\n/** One print screen's discovery results and event subscriptions. Create a new session after disposal. */\nexport class BrotherPrinterSession {\n #closed = false;\n #printers: BRLMChannelResult[] = [];\n #listeners: Promise<PluginListenerHandle>[] = [];\n #listening?: Promise<void>;\n #disposal?: Promise<void>;\n readonly #storage?: BrotherPrinterStorage;\n readonly #storageKey: string;\n\n constructor(options: BrotherPrinterSessionOptions = {}) {\n this.#storage = options.storage;\n this.#storageKey = `${options.storagePrefix ?? 'brotherprint:'}last-printer`;\n }\n\n get closed(): boolean {\n return this.#closed;\n }\n\n get printers(): readonly BRLMChannelResult[] {\n return this.#printers;\n }\n\n search(options: BRLMSearchOption, model?: BRLMPrinterModelName): Promise<readonly BRLMChannelResult[]> {\n return this.#discover(() => discoverPrinters(options, model, () => !this.#closed));\n }\n\n prepare(\n options: BRLMSearchOption,\n model: BRLMPrinterModelName,\n previous?: BRLMChannelResult | null,\n ): Promise<readonly BRLMChannelResult[]> {\n return this.#discover(async () => {\n const saved = previous === undefined ? await this.#readSavedPrinter().catch(() => undefined) : previous;\n if (this.#closed) return [];\n return preparePrinters(options, model, saved, () => !this.#closed);\n });\n }\n\n async #readSavedPrinter(): Promise<BRLMChannelResult | undefined> {\n const value = await this.#storage?.get(this.#storageKey);\n if (!value) return undefined;\n const channel = JSON.parse(value);\n if (\n channel &&\n Object.values(BRLMPrinterPort).includes(channel.port) &&\n ['modelName', 'channelInfo', 'serialNumber', 'macAddress', 'nodeName', 'location'].every(\n (key) => typeof channel[key] === 'string',\n )\n )\n return channel;\n return undefined;\n }\n\n /** Forget the remembered connection. Storage removal errors propagate to the caller. */\n async clearSavedPrinter(): Promise<void> {\n await this.#storage?.remove(this.#storageKey);\n }\n\n async #savePrinter(options: BRLMPrintOptions): Promise<void> {\n if (!this.#storage || !options.port || !options.channelInfo?.trim()) return;\n const found = this.#printers.find(\n (printer) => printer.port === options.port && printer.channelInfo === options.channelInfo,\n );\n const channel: BRLMChannelResult = {\n serialNumber: '',\n macAddress: '',\n nodeName: '',\n location: '',\n ...found,\n port: options.port,\n channelInfo: options.channelInfo,\n modelName: options.modelName,\n };\n await this.#storage.set(this.#storageKey, JSON.stringify(channel));\n }\n\n #discover(run: () => Promise<BRLMChannelResult[]>): Promise<readonly BRLMChannelResult[]> {\n return queueConnection(async () => {\n if (this.#closed) return [];\n this.#printers = [];\n return run().then((printers) => {\n if (this.#closed) return [];\n this.#printers = printers;\n return printers;\n });\n });\n }\n\n /** Register print notifications once. Callbacks stop immediately when disposed. */\n listen(events: BrotherPrinterEvents): Promise<void> {\n if (this.#closed) return Promise.resolve();\n if (!this.#listening) {\n this.#listeners = [\n BrotherPrint.addListener(BrotherPrintEventsEnum.onPrint, () => {\n if (!this.#closed) events.onPrint?.();\n }),\n BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintError, (info) => {\n if (!this.#closed) events.onPrintError?.(info);\n }),\n BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintFailedCommunication, (info) => {\n if (!this.#closed) events.onPrintFailedCommunication?.(info);\n }),\n ];\n this.#listening = Promise.all(this.#listeners).then(() => undefined);\n }\n return this.#listening;\n }\n\n /** A closed session cannot start another print. Already started native printing is awaited. */\n async printImage(options: BRLMPrintOptions): Promise<void> {\n if (this.#closed) return;\n if (this.#storage) await this.#savePrinter(options).catch(() => undefined);\n if (!this.#closed) await BrotherPrint.printImage(options);\n }\n\n /** Invalidate pending work immediately, then remove this session's print listeners. */\n dispose(): Promise<void> {\n this.#closed = true;\n this.#printers = [];\n this.#disposal ??= Promise.all(this.#listeners.map((listener) => listener.then((handle) => handle.remove()))).then(\n () => undefined,\n );\n return this.#disposal;\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BRLMPrinterModelName as Model, BRLMPrinterPort as Port } from './brother-printer.enum';
|
|
2
|
+
export const printerPorts = {
|
|
3
|
+
[Model.QL_800]: [Port.usb],
|
|
4
|
+
[Model.QL_810W]: [Port.wifi, Port.usb],
|
|
5
|
+
[Model.QL_820NWB]: [Port.wifi, Port.bluetooth, Port.usb],
|
|
6
|
+
[Model.TD_2320D_203]: [Port.wifi, Port.usb],
|
|
7
|
+
[Model.TD_2030AD]: [Port.usb],
|
|
8
|
+
[Model.TD_2350D_300]: [Port.wifi, Port.bluetooth, Port.usb, Port.bluetoothLowEnergy],
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,KAAK,EAAE,eAAe,IAAI,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEhG,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC1D,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;IAC1B,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IACtC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC;IACxD,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IAC3C,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;IAC7B,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,CAAC;CACrF,CAAC","sourcesContent":["import { BRLMPrinterModelName as Model, BRLMPrinterPort as Port } from './brother-printer.enum';\n\nexport const printerPorts: Record<Model, readonly Port[]> = {\n [Model.QL_800]: [Port.usb],\n [Model.QL_810W]: [Port.wifi, Port.usb],\n [Model.QL_820NWB]: [Port.wifi, Port.bluetooth, Port.usb],\n [Model.TD_2320D_203]: [Port.wifi, Port.usb],\n [Model.TD_2030AD]: [Port.usb],\n [Model.TD_2350D_300]: [Port.wifi, Port.bluetooth, Port.usb, Port.bluetoothLowEnergy],\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BRLMPrinterModelName, BRLMPrinterPort } from './brother-printer.enum';
|
|
2
|
+
/** Common display names for connection transports. */
|
|
3
|
+
export declare function brotherPrinterPortLabel(port: BRLMPrinterPort | undefined): string;
|
|
4
|
+
/** Connection choices for the existing models. USB is Android-only; wifi also covers Ethernet. */
|
|
5
|
+
export declare function brotherPrinterPorts(model: string, isAndroid?: boolean): BRLMPrinterPort[];
|
|
6
|
+
/** Keep a supported saved port; otherwise prefer USB for QL-800/810W on Android. */
|
|
7
|
+
export declare function resolveBrotherPrinterPort(model: string, saved?: BRLMPrinterPort): BRLMPrinterPort | undefined;
|
|
8
|
+
/** Match discovery names to an existing model enum, including documented product aliases. */
|
|
9
|
+
export declare function brotherPrinterModel(name: string): BRLMPrinterModelName | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Capacitor } from '@capacitor/core';
|
|
2
|
+
import { BRLMPrinterModelName, BRLMPrinterPort } from './brother-printer.enum';
|
|
3
|
+
import { printerPorts } from './models';
|
|
4
|
+
/** Common display names for connection transports. */
|
|
5
|
+
export function brotherPrinterPortLabel(port) {
|
|
6
|
+
switch (port) {
|
|
7
|
+
case BRLMPrinterPort.wifi:
|
|
8
|
+
return 'Wi-Fi';
|
|
9
|
+
case BRLMPrinterPort.bluetooth:
|
|
10
|
+
return 'Bluetooth';
|
|
11
|
+
case BRLMPrinterPort.bluetoothLowEnergy:
|
|
12
|
+
return 'Bluetooth LE';
|
|
13
|
+
case BRLMPrinterPort.usb:
|
|
14
|
+
return 'USB';
|
|
15
|
+
default:
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Connection choices for the existing models. USB is Android-only; wifi also covers Ethernet. */
|
|
20
|
+
export function brotherPrinterPorts(model, isAndroid = Capacitor.getPlatform() === 'android') {
|
|
21
|
+
if (!Object.values(BRLMPrinterModelName).includes(model))
|
|
22
|
+
return [];
|
|
23
|
+
return printerPorts[model].filter((port) => isAndroid || port !== BRLMPrinterPort.usb);
|
|
24
|
+
}
|
|
25
|
+
/** Keep a supported saved port; otherwise prefer USB for QL-800/810W on Android. */
|
|
26
|
+
export function resolveBrotherPrinterPort(model, saved) {
|
|
27
|
+
const ports = brotherPrinterPorts(model);
|
|
28
|
+
if (saved && ports.includes(saved))
|
|
29
|
+
return saved;
|
|
30
|
+
if (ports.includes(BRLMPrinterPort.usb) &&
|
|
31
|
+
(model === BRLMPrinterModelName.QL_800 || model === BRLMPrinterModelName.QL_810W))
|
|
32
|
+
return BRLMPrinterPort.usb;
|
|
33
|
+
return ports[0];
|
|
34
|
+
}
|
|
35
|
+
/** Match discovery names to an existing model enum, including documented product aliases. */
|
|
36
|
+
export function brotherPrinterModel(name) {
|
|
37
|
+
const key = name
|
|
38
|
+
.trim()
|
|
39
|
+
.toUpperCase()
|
|
40
|
+
.replace(/^BROTHER\s+/, '')
|
|
41
|
+
.replace(/[-_ ]/g, '');
|
|
42
|
+
// Product names omit TD resolution; QL-820NWBc and TD-2030A use the existing enum spellings.
|
|
43
|
+
const product = key === 'QL820NWBC' ? 'QL820NWB' : key === 'TD2030A' ? 'TD2030AD' : key;
|
|
44
|
+
return Object.values(BRLMPrinterModelName).find((model) => model.replace(/_/g, '') === product || model.replace(/_(203|300)$/, '').replace(/_/g, '') === product);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.js","sourceRoot":"","sources":["../../src/printer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,sDAAsD;AACtD,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,eAAe,CAAC,IAAI;YACvB,OAAO,OAAO,CAAC;QACjB,KAAK,eAAe,CAAC,SAAS;YAC5B,OAAO,WAAW,CAAC;QACrB,KAAK,eAAe,CAAC,kBAAkB;YACrC,OAAO,cAAc,CAAC;QACxB,KAAK,eAAe,CAAC,GAAG;YACtB,OAAO,KAAK,CAAC;QACf;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED,kGAAkG;AAClG,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C,CAAC,IAAI,CAC7C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,OAAO,CACjH,CAAC;AACJ,CAAC","sourcesContent":["import { Capacitor } from '@capacitor/core';\n\nimport { BRLMPrinterModelName, BRLMPrinterPort } from './brother-printer.enum';\nimport { printerPorts } from './models';\n\n/** Common display names for connection transports. */\nexport function brotherPrinterPortLabel(port: BRLMPrinterPort | undefined): string {\n switch (port) {\n case BRLMPrinterPort.wifi:\n return 'Wi-Fi';\n case BRLMPrinterPort.bluetooth:\n return 'Bluetooth';\n case BRLMPrinterPort.bluetoothLowEnergy:\n return 'Bluetooth LE';\n case BRLMPrinterPort.usb:\n return 'USB';\n default:\n return '';\n }\n}\n\n/** Connection choices for the existing models. USB is Android-only; wifi also covers Ethernet. */\nexport function brotherPrinterPorts(\n model: string,\n isAndroid = Capacitor.getPlatform() === 'android',\n): BRLMPrinterPort[] {\n if (!Object.values(BRLMPrinterModelName).includes(model as BRLMPrinterModelName)) return [];\n return printerPorts[model as BRLMPrinterModelName].filter((port) => isAndroid || port !== BRLMPrinterPort.usb);\n}\n\n/** Keep a supported saved port; otherwise prefer USB for QL-800/810W on Android. */\nexport function resolveBrotherPrinterPort(model: string, saved?: BRLMPrinterPort): BRLMPrinterPort | undefined {\n const ports = brotherPrinterPorts(model);\n if (saved && ports.includes(saved)) return saved;\n if (\n ports.includes(BRLMPrinterPort.usb) &&\n (model === BRLMPrinterModelName.QL_800 || model === BRLMPrinterModelName.QL_810W)\n )\n return BRLMPrinterPort.usb;\n return ports[0];\n}\n\n/** Match discovery names to an existing model enum, including documented product aliases. */\nexport function brotherPrinterModel(name: string): BRLMPrinterModelName | undefined {\n const key = name\n .trim()\n .toUpperCase()\n .replace(/^BROTHER\\s+/, '')\n .replace(/[-_ ]/g, '');\n // Product names omit TD resolution; QL-820NWBc and TD-2030A use the existing enum spellings.\n const product = key === 'QL820NWBC' ? 'QL820NWB' : key === 'TD2030A' ? 'TD2030AD' : key;\n return Object.values(BRLMPrinterModelName).find(\n (model) => model.replace(/_/g, '') === product || model.replace(/_(203|300)$/, '').replace(/_/g, '') === product,\n );\n}\n"]}
|