Skip to content

Commit

Permalink
Replace start/stop with scan/AbortController
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored and kenchris committed Aug 21, 2019
1 parent 95ff627 commit db34ede
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions index.html
Expand Up @@ -754,7 +754,7 @@ <h4>
}
};

reader.start();
reader.scan();
</pre>
</aside>

Expand All @@ -773,7 +773,7 @@ <h4>
</p>
<pre class="highlight">
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) }`);
Expand Down Expand Up @@ -809,7 +809,7 @@ <h4>
}
});

reader.start();
reader.scan();

const writer = new NFCWriter();
writer.push({
Expand Down Expand Up @@ -849,7 +849,7 @@ <h4>
console.log("=== data ===\n" + record.toText());
}
};
reader.start();
reader.scan();

const writer = new NFCWriter();
writer.push("Pushing data is fun!", {target: "tag", ignoreRead: false});
Expand Down Expand Up @@ -1664,8 +1664,7 @@ <h2>The <dfn>NDEFRecordType</dfn> string</h2>
attribute EventHandler onreading;
attribute EventHandler onerror;

void start();
void stop();
void scan(optional NFCScanOptions options={});
};

[Constructor(DOMString type, NFCReadingEventInit readingEventInitDict), SecureContext, Exposed=Window]
Expand Down Expand Up @@ -2110,6 +2109,18 @@ <h3>The <dfn>NFCReaderOptions</dfn> dictionary</h3>
</p>
</section>

<section data-dfn-for="NFCScanOptions"> <h3>The <dfn>NFCScanOptions</dfn> dictionary</h3>
<pre class="idl">
dictionary NFCScanOptions {
AbortSignal? signal;
};
</pre>
<p>
The <dfn>signal</dfn> property allows to abort
the <a href="#dom-nfcreader-scan">scan()</a> operation.
</p>
</section>

<section id="writing-or-pushing-content">
<h3><dfn>Writing or pushing content</dfn></h3>
<p>
Expand Down Expand Up @@ -2969,7 +2980,7 @@ <h3><dfn>Writing or pushing content</dfn></h3>
In order to receive <a>NFC content</a>, the client needs to attach an
event listener for the "`reading`" event on an
{{NFCReader}} instance and then activate it by calling
<a>NFCReader.start()</a>.
<a>NFCReader.scan()</a>.
</p>
<p>
Each {{NFCReader}} can filter the <a>NFC content</a> based on
Expand Down Expand Up @@ -3110,23 +3121,27 @@ <h3><dfn>Writing or pushing content</dfn></h3>
</ol>
</section>

<section> <h3>The <strong>start()</strong> method</h3>
<section> <h3>The <strong>scan()</strong> method</h3>
<p>
The section [[[#steps-receiving]]] uses {{NFCReader}} instances to match
incoming <a>NFC content</a>.
</p>
<p>
Multiple consecutive calls to the <a data-link-for="NFCReader">start()</a>
Multiple consecutive calls to the <a data-link-for="NFCReader">scan()</a>
method from the same <a>origin</a> create filters which are in OR relationship.
</p>
<p>
When the <dfn>NFCReader.start</dfn> method is invoked, the UA
When the <dfn>NFCReader.scan</dfn> method is invoked, the UA
MUST run the following
<dfn id="steps-listen">NFC listen algorithm</dfn>:
<ol class=algorithm>
<li>
Let |reader:NFCReader| be the {{NFCReader}} instance.
</li>
<li>
Let |signal:AbortSignal| be the |options|’ dictionary member
of the same name if present, or `null` otherwise.
</li>
<li>
If there is no underlying <a>NFC Adapter</a>, or if a connection cannot
be established, then
Expand Down Expand Up @@ -3163,6 +3178,22 @@ <h3><dfn>Writing or pushing content</dfn></h3>
</li>
</ol>
</li>
<li>
If |signal|’s [= AbortSignal/aborted flag =] is set, then return.
</li>
<li>
If |signal| is not `null`, then
<a data-cite="dom#abortsignal-add">add the following abort steps</a> to |signal|:
<ol>
<li>
Remove the {{NFCReader}} instance from the <a>activated reader objects</a>.
</li>
<li>
If the <a>activated reader objects</a> [= list/is empty =], then make a request
to stop listening to <a>NDEF message</a>s on all <a>NFC adapter</a>s.
</li>
</ol>
</li>
<li>
Run the following steps <a>in parallel</a>:
<ol>
Expand Down Expand Up @@ -3248,7 +3279,7 @@ <h3><dfn>Writing or pushing content</dfn></h3>
<li>
Otherwise, if the user has earlier denied permission for the calling
<a>origin</a> for all future calls of
<a data-link-for="NFCReader">start()</a>
<a data-link-for="NFCReader">scan()</a>
as well, then return `false`.
</li>
<li>
Expand All @@ -3275,22 +3306,6 @@ <h3><dfn>Writing or pushing content</dfn></h3>
</p>
</section>

<section> <h3>The <strong>stop()</strong> method</h3>
<p>
When the <dfn>NFCReader.stop</dfn> method is invoked, the UA
MUST run the following algorithm:
<ol class=algorithm>
<li>
Remove the {{NFCReader}} instance from the <a>activated reader objects</a>.
</li>
<li>
If the <a>activated reader objects</a> [= list/is empty =], then make a request
to stop listening to <a>NDEF message</a>s on all <a>NFC adapter</a>s.
</li>
</ol>
</p>
</section>

</section>

<section id="steps-receiving">
Expand Down

0 comments on commit db34ede

Please sign in to comment.