Skip to content

Commit

Permalink
Reapply #565 (#600)
Browse files Browse the repository at this point in the history
* Remove ignoreRead and add info on how to implement manually (#571)

* Remove ignoreRead and add info on how to implement manually

* Reapply #565: remove filtering

Signed-off-by: Zoltan Kis <zoltan.kis@intel.com>

Co-authored-by: Kenneth Rohde Christiansen <kenneth.r.christiansen@intel.com>
  • Loading branch information
zolkis and kenchris committed Sep 18, 2020
1 parent 4520de9 commit 8e526a1
Showing 1 changed file with 21 additions and 159 deletions.
180 changes: 21 additions & 159 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1246,15 +1246,16 @@ <h4>
<section> <h3>Save and restore game progress with an NFC tag</h3>
<p>
Filtering of relevant data sources can be done by the use of
the <a>NDEFScanOptions</a>. Below we use the custom record identifier
"`my-game-progress`" as a relative URL so that when we read the data, we
immediately update the game progress by issuing a write with a custom NDEF
data layout.
a custom record identifier, in this case "`my-game-progress`".
When we read the data, we immediately update the game progress by issuing
a write with a custom NDEF data layout.
</p>
<pre class="example">
const reader = new NDEFReader();
await reader.scan({ id: "my-game-progress" });
await reader.scan();
reader.onreading = async event => {
if (event.message.id !== "my-game-progress")
return;
console.log(`Game state: ${ JSON.stringify(event.message.records) }`);

const encoder = new TextEncoder();
Expand Down Expand Up @@ -1283,9 +1284,7 @@ <h4>
</p>
<pre class="example">
const reader = new NDEFReader();
await reader.scan({
mediaType: "application/*json"
});
await reader.scan();
reader.onreading = event => {
const decoder = new TextDecoder();
for (const record of event.message.records) {
Expand Down Expand Up @@ -1438,7 +1437,7 @@ <h4>
</p>
<pre class="example">
const reader = new NDEFReader();
await reader.scan({ recordType: "example.com:smart-poster" });
await reader.scan();
reader.onreading = event => {
const externalRecord = event.message.records.find(
record => record.type == "example.com:smart-poster"
Expand Down Expand Up @@ -1531,10 +1530,11 @@ <h4>
</pre>
<pre class="example">
const reader = new NDEFReader();
await reader.scan({ recordType: "example.com:shoppingItem" });
await reader.scan();
reader.onreading = event => {
const shoppingItemRecord = event.message.records[0];
if (!shoppingItemRecord) {
if (!shoppingItemRecord ||
shoppingItemRecord.recordType !== "example.com:shoppingItem") {
return;
}

Expand Down Expand Up @@ -1992,7 +1992,8 @@ <h2>The <dfn>record type</dfn> string</h2>
interface NDEFWriter {
constructor();

Promise&lt;undefined&gt; write(NDEFMessageSource message, optional NDEFWriteOptions options={});
Promise&lt;undefined&gt; write(NDEFMessageSource message,
optional NDEFWriteOptions options={});
};

[SecureContext, Exposed=Window]
Expand Down Expand Up @@ -2093,26 +2094,6 @@ <h2>The <dfn>record type</dfn> string</h2>
</thead>
<tbody data-link-for="NDEFScanOptions">
<tr>
<td><dfn>[[\Id]]</dfn></td>
<td>`undefined`</td>
<td>
The {{NDEFScanOptions}}.<a>id</a> value.
</td>
</tr>
<tr>
<td><dfn>[[\RecordType]]</dfn></td>
<td>`undefined`</td>
<td>
The {{NDEFScanOptions}}.<a>recordType</a> value.
</td>
</tr>
<tr>
<td><dfn>[[\MediaType]]</dfn></td>
<td>`undefined`</td>
<td>
The {{NDEFScanOptions}}.<a>mediaType</a> value.
</td>
</tr>
<tr>
<td><dfn>[[\Signal]]</dfn></td>
<td>`undefined`</td>
Expand All @@ -2123,13 +2104,6 @@ <h2>The <dfn>record type</dfn> string</h2>
</tbody>
</table>

<p class="note">
Note that the internal slots of {{NDEFReader}} come from the
|options:NDEFScanOptions| passed to <a>NDEFReader.scan()</a>.
Therefore there is maximum one filter associated with any given
{{NDEFReader}} object and successive invocations of <a>NDEFReader.scan()</a>
with new |options:NDEFScanOptions| will replace existing filters.
</p>
<p>
The <dfn data-dfn-for="NDEFReader">onreading</dfn> is an {{EventHandler}}
which is called to notify that new reading is available.
Expand Down Expand Up @@ -2364,60 +2338,18 @@ <h3>The <dfn>NDEFWriteOptions</dfn> dictionary</h3>
<section data-dfn-for="NDEFScanOptions">
<h3>The <dfn>NDEFScanOptions</dfn> dictionary</h3>
<p>
To describe which messages an application is interested in, the
<a>NDEFScanOptions</a> dictionary is used:
To stop listening to NDEF messages, an [= AbortSignal/aborted flag =]
can be used in the <a>NDEFScanOptions</a> dictionary:
</p>
<pre class="idl">
dictionary NDEFScanOptions {
USVString id;
USVString recordType;
USVString mediaType;
AbortSignal? signal;
AbortSignal signal;
};
</pre>
<p>
The <dfn>signal</dfn> property allows to abort the
{{NDEFReader/scan()}} operation.
</p>
<p>
The <dfn>id</dfn> property
denotes the string value which is used for matching the
<a>record identifier</a> of each
<a>NDEFRecord</a> object in an <a>NDEF message</a>.
If the dictionary member is not present,
then it will be ignored by the
<a href="#steps-listen">NFC listen algorithm</a>.
</p>
<p>
The <dfn>recordType</dfn> property
denotes the string value which is used for matching the
<a>record type</a> of each
<a>NDEFRecord</a> object in an <a>NDEF message</a>.
If the dictionary member is not present,
then it will be ignored by the
<a href="#steps-listen">NFC listen algorithm</a>.
</p>
<p>
The <dfn>mediaType</dfn> property
denotes the <a>match pattern</a> which is used for matching the
{{NDEFRecord/mediaType}} property of each
<a>NDEFRecord</a> object in an <a>NDEF message</a>.
</p>
<pre
title="Filter accepting only JSON content"
class="example highlight">
const options = {
mediaType: "application/*json" // any JSON-based MIME type
}
</pre>
<pre
title="Filter which only accepts binary content for a custom record identifier"
class="example highlight">
const options = {
id: "my-restaurant-daily-menu",
mediaType: "application/octet-stream"
}
</pre>
</section> <!-- NDEFScanOptions -->

<section id="writing-content">
Expand Down Expand Up @@ -3522,28 +3454,6 @@ <h3><dfn>Writing content</dfn></h3>
then the <a>UA</a> MUST listen to <a>NDEF message</a>s on all connected
NFC adapters.
</p>
<p>
Each {{NDEFReader}} can accept <a>NDEF message</a>s based on
data type, and record identifier filters.
</p>

<section> <h3>Match patterns</h3>
<div>
A <dfn>match pattern</dfn> is defined by the following ABNF:
<pre class="abnf">
match-pattern = top-level-type "/" [ tree "." ] subtype [ "+" suffix ] [ ";" parameters ]
top-level-type = "*" / &lt; VCHAR except "/" and "*" &gt;
subtype = "*" / &lt; VCHAR except "+" &gt;
</pre>
A <a>match pattern</a> is a
<a href="http://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html#tag_02_13_03">
glob</a> used for matching <a>MIME type</a>s,
for instance the pattern "`application/*+json`" matches
"`application/calendar+json`", but does not match
"`application/json`". The pattern
"`*/*json`", on the other hand, matches both.
</div>
</section>

<section> <h3>The <strong>scan()</strong> method</h3>
<p>
Expand All @@ -3570,18 +3480,6 @@ <h3><dfn>Writing content</dfn></h3>
If |key| equals "`signal`" and |value| is not `undefined`, set
|reader|.<a>[[\Signal]]</a> to |value|.
</li>
<li>
Otherwise, if |key| equals "`id`", set
|reader|.<a>[[\Id]]</a> to |value|.
</li>
<li>
Otherwise, if |key| equals "`recordType`", set
|reader|.<a>[[\RecordType]]</a> to |value|.
</li>
<li>
Otherwise, if |key| equals "`mediaType`", set
|reader|.<a>[[\MediaType]]</a> to |value|.
</li>
</ol>
</li>
<li>
Expand Down Expand Up @@ -3726,49 +3624,13 @@ <h3><dfn>Writing content</dfn></h3>
<ol class=algorithm>
<li>
[= list/For each =] {{NDEFReader}} instance |reader:NDEFReader| in
the <a>activated reader objects</a>, run the following sub-steps:
the <a>activated reader objects</a>,
<ol>
<li>
[= list/For each =] |record:NDEFRecord| in |message:NDEFMessage|,
<ol>
<li>
Let |matched:boolean| be `false`.
</li>
<li>
If |reader|.<a>[[\Id]]</a> is not `undefined` and is not equal
to |record|'s <a href="#dom-ndefrecord-id">id</a>,
[= iteration/continue =].
If it is equal, set |matched| to `true`.
</li>
<li>
If |reader|.<a>[[\RecordType]]</a> is not `undefined` and is
not equal to |record|'s
<a href="#dom-ndefrecord-recordtype">recordType</a>,
[= iteration/continue =].
If it is equal, set |matched| to `true`.
</li>
<li>
If |reader|.<a>[[\MediaType]]</a> is not `undefined` and is not
equal to
|record|'s <a href="#dom-ndefrecord-mediatype">mediaType</a>,
[= iteration/continue =].
If it is equal, set |matched| to `true`.
</li>
<li>
If |matched| is `true`,
<ol>
<li>
<a>fire an event</a> named "`reading`"
at |reader| using <a>NDEFReadingEvent</a> with its
<a>serialNumber</a> attribute initialized to |serialNumber|
and <a>message</a> attribute initialized to |message|.
</li>
<li>
[= iteration/Break =].
</li>
</ol>
</li>
</ol>
<a>fire an event</a> named "`reading`" at |reader| using
<a>NDEFReadingEvent</a> with its <a>serialNumber</a> attribute
initialized to |serialNumber| and <a>message</a> attribute
initialized to |message|.
</li>
</ol>
</li>
Expand Down

0 comments on commit 8e526a1

Please sign in to comment.