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.
40 lines
1.0 KiB
40 lines
1.0 KiB
import { NFC } from 'nfc-pcsc'
|
|
import { Logger } from './statuslogger.js'
|
|
import chalk from 'chalk'
|
|
import EventEmitter from 'events'
|
|
import fs from 'fs'
|
|
|
|
export const ICCard = (path) => {
|
|
const logger = Logger(chalk.magenta('[PCSC]'))
|
|
const nfc = new NFC()
|
|
const emitter = new EventEmitter()
|
|
emitter.alt = new EventEmitter()
|
|
|
|
nfc.on('error', err => {
|
|
logger.error('Error', err);
|
|
});
|
|
|
|
nfc.on('reader', reader => {
|
|
logger.info('Card reader found: ' + reader.name)
|
|
|
|
reader.on('card', card => {
|
|
logger.info(`Card ${card.uid} scanned`)
|
|
|
|
if (!fs.existsSync(path + card.uid + '.track_0')) {
|
|
logger.info('Data for card uid not found, assuming new')
|
|
emitter.alt.emit('new-card', card.uid)
|
|
emitter.emit('new-card', card.uid)
|
|
} else {
|
|
logger.info('Data for card uid found!')
|
|
emitter.alt.emit('old-card', card.uid )
|
|
emitter.emit('old-card', card.uid )
|
|
}
|
|
})
|
|
|
|
reader.on('error', err => {
|
|
logger.error('Error', err);
|
|
});
|
|
})
|
|
|
|
return emitter
|
|
}
|
|
|