added startScanning method

This commit is contained in:
SrGooglo 2023-06-20 15:53:52 +00:00
parent 3a1127ef9e
commit 0be9adf117

View File

@ -1,5 +1,6 @@
import Core from "evite/src/core"
import TapShareDialog from "components/TapShare/Dialog"
import { Nfc, NfcUtils, NfcTagTechType } from "@capawesome-team/capacitor-nfc"
export default class NFC extends Core {
static refName = "NFC"
@ -13,6 +14,7 @@ export default class NFC extends Core {
public = {
incompatible: null,
scanning: false,
startScanning: this.startScanning.bind(this),
instance: function () { return this.instance }.bind(this),
subscribe: this.subscribe.bind(this),
unsubscribe: this.unsubscribe.bind(this),
@ -25,8 +27,12 @@ export default class NFC extends Core {
this.instance = new NDEFReader()
this.startScanning()
}
async startScanning() {
try {
navigator.permissions.query({ name: "nfc" })
//await navigator.permissions.query({ name: "nfc" })
this.instance.scan()
@ -43,6 +49,11 @@ export default class NFC extends Core {
}
subscribe(callback) {
// check if scan service is available, if not try to initialize
if (this.public.scanning === false) {
this.startScanning()
}
this.subscribers.push(callback)
console.debug(`[NFC] SUBSCRIBED >`, this.subscribers.length)