w3c / web-nfc

Web NFC
https://w3c.github.io/web-nfc/
Other
313 stars 69 forks source link

NDEF Read triggered when writting an NDEF #551

Closed OlivierGrenoble closed 3 years ago

OlivierGrenoble commented 4 years ago

When writting an NDEF with writer.write(), I have noticed that the NFC service is immediately processing the NDEF freshly written. I have been told to run scan() and discard the onreading events.

Isn't that a pity that it is not the default behavior? When writing to a tag, one seldom needs the processing by NFC service of the NDEF freshly written. That makes the things harder for someone wanting to write an NDEF into an NFC tag.

DonnaWuDongxia commented 4 years ago

As @beaufortfrancois mentioned, the CL will leave "Android NFC Reader Mode" enabled after at least one successful write/scan Web NFC operation has been called. But is will be disabled when the site is invisible, or the Mojo connection is closed. If there is no other NFC usage in Chromium, is it unacceptable to keep the device in NFC ReadMode while a WebNFC user is in foreground?

OlivierGrenoble commented 4 years ago

As a temporary workaround, when writing an NDEF, I catch all the NFC read events during 10 seconds. You can try it here: https://www.myst25.com/ST25NFCWebApp/

beaufortfrancois commented 4 years ago

@OlivierGrenoble Thanks for sharing your workaround. Quick question: It looks like you use the same readerAbortController object in writeNdef and readNfcTagContent. Is this expected that you abort the one in writeNdef when you call cancelReadOperation?

OlivierGrenoble commented 4 years ago

@OlivierGrenoble Thanks for sharing your workaround. Quick question: It looks like you use the same readerAbortController object in writeNdef and readNfcTagContent. Is this expected that you abort the one in writeNdef when you call cancelReadOperation?

It works but I think that this could be done in a better way. cancelReadOperation() will not abort the readerAbortController used by the write function because nfcAction is not equal to nfcActions.NFC_READ_ON_GOING. Yeah, it could be better :-S

kenchris commented 4 years ago

Hi there, we are most likely going to join the objects #561 which should make handling read and write easier after we handle all the details.

beaufortfrancois commented 3 years ago

NDEFReader and NDEFWriter have been merged into NDEFReader. See https://github.com/w3c/web-nfc/blob/gh-pages/EXPLAINER.md#changes-done-after-origin-trial-ot

With updated spec examples, I believe we're good now: https://w3c.github.io/web-nfc/#handling-initial-reads-while-writing Can we close issue?

kenchris commented 3 years ago

Sure