[web-nfc] Expose WebNFC to workers (#293)

beaufortfrancois has just created a new issue for https://github.com/w3c/web-nfc:

== Expose WebNFC to workers ==
Moving Web APIs out of the main thread seems like [a good pattern](https://dassur.ma/things/when-workers/) for the Web and I'd argue WebNFC would be a great candidate.

```js
// worker.js
self.addEventListener("message", { action } => {
  const reader = new NFCReader({url: document.baseURI, recordType: "json"});
  reader.addEventListener("reading", { message } => {
    for (const record of message.records) {
      const data = record.data();
      self.postMessage({ data });
  });
  reader.start();
});

// main.js
const worker = new Worker();
myWorker.addEventListener("message", { data } => {
  console.log('NFC message read from worker', data);
});
worker.postMessage({ action: "read" });
```

Please view or discuss this issue at https://github.com/w3c/web-nfc/issues/293 using your GitHub account

Received on Monday, 12 August 2019 11:15:17 UTC