UNPKG

@mastashake08/web-iot

Version:

Connect to your IoT devices via usb, serial, NFC or Serial. Allows for callback integration and streaming *coming soon*

43 lines (40 loc) 948 B
import { WebIOT } from './WebIOT' export class NFCManager extends WebIOT { #nfc = {} constructor (debug = false) { super(debug) if ('NDEFReader' in window) { /* Scan and write NFC tags */ this.startNFC() } else { alert('NFC is not supported in your browser') } } startNFC () { this.nfc = new NDEFReader() } async readNFCData (readCb = (event) => {console.log(event)}, errorCb = (event) => console.log(event)) { try { await this.nfc.scan() this.nfc.onreading = readCb } catch(e) { errorCb(e) } } async writeNFCData (records, errorCb = (event) => console.log(event)) { try { await this.nfc.write(records) } catch (e) { errorCb(e) } } async lockNFCTag(errorCb = (event) => console.log(event)) { try { await this.nfc.makeReadOnly() } catch(e) { errorCb(e) } } static generateNFC () { return new NDEFReader() } }