You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
import { NFC } from 'nfc-pcsc'
|
|
import fetch from 'node-fetch'
|
|
|
|
console.log('[ ][INF][EABU]: Starting up (if this hangs check if pcscd is running)')
|
|
const nfc = new NFC()
|
|
const status = {
|
|
card: null
|
|
}
|
|
|
|
console.log('[ ][INF][EABU]: NFC Initialized')
|
|
nfc.on('error', err => {
|
|
console.error('[!][ERR][PCSC]:', err);
|
|
});
|
|
nfc.on('reader', reader => {
|
|
reader.aid = 'F222222222';
|
|
reader.on('card', card => {
|
|
console.log(`[C][INF][PCSC]: Card ${card.uid} scanned`)
|
|
if (status.card === null) {
|
|
status.card = card.uid
|
|
console.log(`[C][INF][YACE]: Telling YACE to insert ${card.uid}`)
|
|
fetch('http://localhost:8082/api/v1/insertCard?cardname=' + card.uid, { method: 'POST' })
|
|
} else {
|
|
console.log(`[C][INF][EABU]: Ignoring as we already have a card...`)
|
|
}
|
|
})
|
|
reader.on('error', err => {
|
|
console.error('[!][ERR][PCSC]:', err);
|
|
});
|
|
})
|
|
|
|
|
|
const pollYACE = () => {
|
|
if (status.card !== null) {
|
|
fetch('http://localhost:8082/api/v1/insertedCard')
|
|
.then(res => res.json())
|
|
.then(bool => console.log('[ ][INF][YACE] Emulator card inserted: ' + bool.inserted))
|
|
fetch('http://localhost:8082/api/v1/hasCard')
|
|
.then(res => res.json())
|
|
.then(bool => {
|
|
console.log('[ ][INF][YACE] Emulator card present: ' + bool)
|
|
if (!bool) {
|
|
status.card = null
|
|
fetch('http://localhost:8082/api/v1/insertCard?cardname=dummy', { method: 'POST' })
|
|
}
|
|
})
|
|
.finally(() => setTimeout(pollYACE, 100))
|
|
} else {
|
|
setTimeout(pollYACE, 200)
|
|
}
|
|
}
|
|
|
|
pollYACE()
|
|
|