smartcard 2.0.2 → 2.0.3
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/lib/devices.js +21 -4
- package/package.json +1 -1
package/lib/devices.js
CHANGED
|
@@ -246,10 +246,27 @@ class Devices extends EventEmitter {
|
|
|
246
246
|
const reader = readers.find(r => r.name === readerName);
|
|
247
247
|
|
|
248
248
|
if (reader) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
let card;
|
|
250
|
+
try {
|
|
251
|
+
// First try with both T=0 and T=1 protocols
|
|
252
|
+
card = await reader.connect(
|
|
253
|
+
SCARD_SHARE_SHARED,
|
|
254
|
+
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1
|
|
255
|
+
);
|
|
256
|
+
} catch (dualProtocolErr) {
|
|
257
|
+
// If dual protocol fails (e.g., SCARD_W_UNRESPONSIVE_CARD),
|
|
258
|
+
// fallback to T=0 only (issue #34)
|
|
259
|
+
if (dualProtocolErr.message &&
|
|
260
|
+
dualProtocolErr.message.toLowerCase().includes('unresponsive')) {
|
|
261
|
+
card = await reader.connect(
|
|
262
|
+
SCARD_SHARE_SHARED,
|
|
263
|
+
SCARD_PROTOCOL_T0
|
|
264
|
+
);
|
|
265
|
+
} else {
|
|
266
|
+
// Re-throw if it's a different error
|
|
267
|
+
throw dualProtocolErr;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
253
270
|
|
|
254
271
|
state.card = card;
|
|
255
272
|
|