From db34edec467354b05b80f9fac8ab739827d4af51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Mon, 19 Aug 2019 16:37:30 +0200 Subject: [PATCH] Replace start/stop with scan/AbortController --- index.html | 69 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index afe773a..210060f 100644 --- a/index.html +++ b/index.html @@ -754,7 +754,7 @@

} }; -reader.start(); +reader.scan(); @@ -773,7 +773,7 @@

 const reader = new NFCReader({url: "https://mygame.com/mypath/mygame"});
-reader.start();
+reader.scan();
 reader.onreading = async event => {
   console.log(`Source:     ${ event.message.url }`);
   console.log(`Game state: ${ JSON.stringify(event.message.records) }`);
@@ -809,7 +809,7 @@ 

} }); -reader.start(); +reader.scan(); const writer = new NFCWriter(); writer.push({ @@ -849,7 +849,7 @@

console.log("=== data ===\n" + record.toText()); } }; -reader.start(); +reader.scan(); const writer = new NFCWriter(); writer.push("Pushing data is fun!", {target: "tag", ignoreRead: false}); @@ -1664,8 +1664,7 @@

The NDEFRecordType string

attribute EventHandler onreading; attribute EventHandler onerror; - void start(); - void stop(); + void scan(optional NFCScanOptions options={}); }; [Constructor(DOMString type, NFCReadingEventInit readingEventInitDict), SecureContext, Exposed=Window] @@ -2110,6 +2109,18 @@

The NFCReaderOptions dictionary

+

The NFCScanOptions dictionary

+
+      dictionary NFCScanOptions {
+        AbortSignal? signal;
+      };
+    
+

+ The signal property allows to abort + the scan() operation. +

+
+

Writing or pushing content

@@ -2969,7 +2980,7 @@

Writing or pushing content

In order to receive NFC content, the client needs to attach an event listener for the "`reading`" event on an {{NFCReader}} instance and then activate it by calling - NFCReader.start(). + NFCReader.scan().

Each {{NFCReader}} can filter the NFC content based on @@ -3110,23 +3121,27 @@

Writing or pushing content

-

The start() method

+

The scan() method

The section [[[#steps-receiving]]] uses {{NFCReader}} instances to match incoming NFC content.

- Multiple consecutive calls to the start() + Multiple consecutive calls to the scan() method from the same origin create filters which are in OR relationship.

- When the NFCReader.start method is invoked, the UA + When the NFCReader.scan method is invoked, the UA MUST run the following NFC listen algorithm:

  1. Let |reader:NFCReader| be the {{NFCReader}} instance.
  2. +
  3. + Let |signal:AbortSignal| be the |options|’ dictionary member + of the same name if present, or `null` otherwise. +
  4. If there is no underlying NFC Adapter, or if a connection cannot be established, then @@ -3163,6 +3178,22 @@

    Writing or pushing content

+
  • + If |signal|’s [= AbortSignal/aborted flag =] is set, then return. +
  • +
  • + If |signal| is not `null`, then + add the following abort steps to |signal|: +
      +
    1. + Remove the {{NFCReader}} instance from the activated reader objects. +
    2. +
    3. + If the activated reader objects [= list/is empty =], then make a request + to stop listening to NDEF messages on all NFC adapters. +
    4. +
    +
  • Run the following steps in parallel:
      @@ -3248,7 +3279,7 @@

      Writing or pushing content

    1. Otherwise, if the user has earlier denied permission for the calling origin for all future calls of - start() + scan() as well, then return `false`.
    2. @@ -3275,22 +3306,6 @@

      Writing or pushing content

  • -

    The stop() method

    -

    - When the NFCReader.stop method is invoked, the UA - MUST run the following algorithm: -

      -
    1. - Remove the {{NFCReader}} instance from the activated reader objects. -
    2. -
    3. - If the activated reader objects [= list/is empty =], then make a request - to stop listening to NDEF messages on all NFC adapters. -
    4. -
    -

    -
    -