@@ -1246,15 +1246,16 @@ <h4>
1246
1246
< section > < h3 > Save and restore game progress with an NFC tag</ h3 >
1247
1247
< p >
1248
1248
Filtering of relevant data sources can be done by the use of
1249
- the < a > NDEFScanOptions</ a > . Below we use the custom record identifier
1250
- "`my-game-progress`" as a relative URL so that when we read the data, we
1251
- immediately update the game progress by issuing a write with a custom NDEF
1252
- data layout.
1249
+ a custom record identifier, in this case "`my-game-progress`".
1250
+ When we read the data, we immediately update the game progress by issuing
1251
+ a write with a custom NDEF data layout.
1253
1252
</ p >
1254
1253
< pre class ="example ">
1255
1254
const reader = new NDEFReader();
1256
- await reader.scan({ id: "my-game-progress" } );
1255
+ await reader.scan();
1257
1256
reader.onreading = async event => {
1257
+ if (event.message.id !== "my-game-progress")
1258
+ return;
1258
1259
console.log(`Game state: ${ JSON.stringify(event.message.records) }`);
1259
1260
1260
1261
const encoder = new TextEncoder();
@@ -1283,9 +1284,7 @@ <h4>
1283
1284
</ p >
1284
1285
< pre class ="example ">
1285
1286
const reader = new NDEFReader();
1286
- await reader.scan({
1287
- mediaType: "application/*json"
1288
- });
1287
+ await reader.scan();
1289
1288
reader.onreading = event => {
1290
1289
const decoder = new TextDecoder();
1291
1290
for (const record of event.message.records) {
@@ -1438,7 +1437,7 @@ <h4>
1438
1437
</ p >
1439
1438
< pre class ="example ">
1440
1439
const reader = new NDEFReader();
1441
- await reader.scan({ recordType: "example.com:smart-poster" } );
1440
+ await reader.scan();
1442
1441
reader.onreading = event => {
1443
1442
const externalRecord = event.message.records.find(
1444
1443
record => record.type == "example.com:smart-poster"
@@ -1531,10 +1530,11 @@ <h4>
1531
1530
</ pre >
1532
1531
< pre class ="example ">
1533
1532
const reader = new NDEFReader();
1534
- await reader.scan({ recordType: "example.com:shoppingItem" } );
1533
+ await reader.scan();
1535
1534
reader.onreading = event => {
1536
1535
const shoppingItemRecord = event.message.records[0];
1537
- if (!shoppingItemRecord) {
1536
+ if (!shoppingItemRecord ||
1537
+ shoppingItemRecord.recordType !== "example.com:shoppingItem") {
1538
1538
return;
1539
1539
}
1540
1540
@@ -1992,7 +1992,8 @@ <h2>The <dfn>record type</dfn> string</h2>
1992
1992
interface NDEFWriter {
1993
1993
constructor();
1994
1994
1995
- Promise<undefined> write(NDEFMessageSource message, optional NDEFWriteOptions options={});
1995
+ Promise<undefined> write(NDEFMessageSource message,
1996
+ optional NDEFWriteOptions options={});
1996
1997
};
1997
1998
1998
1999
[SecureContext, Exposed=Window]
@@ -2093,26 +2094,6 @@ <h2>The <dfn>record type</dfn> string</h2>
2093
2094
</ thead >
2094
2095
< tbody data-link-for ="NDEFScanOptions ">
2095
2096
< tr >
2096
- < td > < dfn > [[\Id]]</ dfn > </ td >
2097
- < td > `undefined`</ td >
2098
- < td >
2099
- The {{NDEFScanOptions}}.< a > id</ a > value.
2100
- </ td >
2101
- </ tr >
2102
- < tr >
2103
- < td > < dfn > [[\RecordType]]</ dfn > </ td >
2104
- < td > `undefined`</ td >
2105
- < td >
2106
- The {{NDEFScanOptions}}.< a > recordType</ a > value.
2107
- </ td >
2108
- </ tr >
2109
- < tr >
2110
- < td > < dfn > [[\MediaType]]</ dfn > </ td >
2111
- < td > `undefined`</ td >
2112
- < td >
2113
- The {{NDEFScanOptions}}.< a > mediaType</ a > value.
2114
- </ td >
2115
- </ tr >
2116
2097
< tr >
2117
2098
< td > < dfn > [[\Signal]]</ dfn > </ td >
2118
2099
< td > `undefined`</ td >
@@ -2123,13 +2104,6 @@ <h2>The <dfn>record type</dfn> string</h2>
2123
2104
</ tbody >
2124
2105
</ table >
2125
2106
2126
- < p class ="note ">
2127
- Note that the internal slots of {{NDEFReader}} come from the
2128
- |options:NDEFScanOptions| passed to < a > NDEFReader.scan()</ a > .
2129
- Therefore there is maximum one filter associated with any given
2130
- {{NDEFReader}} object and successive invocations of < a > NDEFReader.scan()</ a >
2131
- with new |options:NDEFScanOptions| will replace existing filters.
2132
- </ p >
2133
2107
< p >
2134
2108
The < dfn data-dfn-for ="NDEFReader "> onreading</ dfn > is an {{EventHandler}}
2135
2109
which is called to notify that new reading is available.
@@ -2364,60 +2338,18 @@ <h3>The <dfn>NDEFWriteOptions</dfn> dictionary</h3>
2364
2338
< section data-dfn-for ="NDEFScanOptions ">
2365
2339
< h3 > The < dfn > NDEFScanOptions</ dfn > dictionary</ h3 >
2366
2340
< p >
2367
- To describe which messages an application is interested in, the
2368
- < a > NDEFScanOptions</ a > dictionary is used :
2341
+ To stop listening to NDEF messages, an [= AbortSignal/aborted flag =]
2342
+ can be used in the < a > NDEFScanOptions</ a > dictionary:
2369
2343
</ p >
2370
2344
< pre class ="idl ">
2371
2345
dictionary NDEFScanOptions {
2372
- USVString id;
2373
- USVString recordType;
2374
- USVString mediaType;
2375
- AbortSignal? signal;
2346
+ AbortSignal signal;
2376
2347
};
2377
2348
</ pre >
2378
2349
< p >
2379
2350
The < dfn > signal</ dfn > property allows to abort the
2380
2351
{{NDEFReader/scan()}} operation.
2381
2352
</ p >
2382
- < p >
2383
- The < dfn > id</ dfn > property
2384
- denotes the string value which is used for matching the
2385
- < a > record identifier</ a > of each
2386
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2387
- If the dictionary member is not present,
2388
- then it will be ignored by the
2389
- < a href ="#steps-listen "> NFC listen algorithm</ a > .
2390
- </ p >
2391
- < p >
2392
- The < dfn > recordType</ dfn > property
2393
- denotes the string value which is used for matching the
2394
- < a > record type</ a > of each
2395
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2396
- If the dictionary member is not present,
2397
- then it will be ignored by the
2398
- < a href ="#steps-listen "> NFC listen algorithm</ a > .
2399
- </ p >
2400
- < p >
2401
- The < dfn > mediaType</ dfn > property
2402
- denotes the < a > match pattern</ a > which is used for matching the
2403
- {{NDEFRecord/mediaType}} property of each
2404
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2405
- </ p >
2406
- < pre
2407
- title ="Filter accepting only JSON content "
2408
- class ="example highlight ">
2409
- const options = {
2410
- mediaType: "application/*json" // any JSON-based MIME type
2411
- }
2412
- </ pre >
2413
- < pre
2414
- title ="Filter which only accepts binary content for a custom record identifier "
2415
- class ="example highlight ">
2416
- const options = {
2417
- id: "my-restaurant-daily-menu",
2418
- mediaType: "application/octet-stream"
2419
- }
2420
- </ pre >
2421
2353
</ section > <!-- NDEFScanOptions -->
2422
2354
2423
2355
< section id ="writing-content ">
@@ -3522,28 +3454,6 @@ <h3><dfn>Writing content</dfn></h3>
3522
3454
then the < a > UA</ a > MUST listen to < a > NDEF message</ a > s on all connected
3523
3455
NFC adapters.
3524
3456
</ p >
3525
- < p >
3526
- Each {{NDEFReader}} can accept < a > NDEF message</ a > s based on
3527
- data type, and record identifier filters.
3528
- </ p >
3529
-
3530
- < section > < h3 > Match patterns</ h3 >
3531
- < div >
3532
- A < dfn > match pattern</ dfn > is defined by the following ABNF:
3533
- < pre class ="abnf ">
3534
- match-pattern = top-level-type "/" [ tree "." ] subtype [ "+" suffix ] [ ";" parameters ]
3535
- top-level-type = "*" / < VCHAR except "/" and "*" >
3536
- subtype = "*" / < VCHAR except "+" >
3537
- </ pre >
3538
- A < a > match pattern</ a > is a
3539
- < a href ="http://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html#tag_02_13_03 ">
3540
- glob</ a > used for matching < a > MIME type</ a > s,
3541
- for instance the pattern "`application/*+json`" matches
3542
- "`application/calendar+json`", but does not match
3543
- "`application/json`". The pattern
3544
- "`*/*json`", on the other hand, matches both.
3545
- </ div >
3546
- </ section >
3547
3457
3548
3458
< section > < h3 > The < strong > scan()</ strong > method</ h3 >
3549
3459
< p >
@@ -3570,18 +3480,6 @@ <h3><dfn>Writing content</dfn></h3>
3570
3480
If |key| equals "`signal`" and |value| is not `undefined`, set
3571
3481
|reader|.< a > [[\Signal]]</ a > to |value|.
3572
3482
</ li >
3573
- < li >
3574
- Otherwise, if |key| equals "`id`", set
3575
- |reader|.< a > [[\Id]]</ a > to |value|.
3576
- </ li >
3577
- < li >
3578
- Otherwise, if |key| equals "`recordType`", set
3579
- |reader|.< a > [[\RecordType]]</ a > to |value|.
3580
- </ li >
3581
- < li >
3582
- Otherwise, if |key| equals "`mediaType`", set
3583
- |reader|.< a > [[\MediaType]]</ a > to |value|.
3584
- </ li >
3585
3483
</ ol >
3586
3484
</ li >
3587
3485
< li >
@@ -3726,49 +3624,13 @@ <h3><dfn>Writing content</dfn></h3>
3726
3624
< ol class =algorithm >
3727
3625
< li >
3728
3626
[= list/For each =] {{NDEFReader}} instance |reader:NDEFReader| in
3729
- the < a > activated reader objects</ a > , run the following sub-steps:
3627
+ the < a > activated reader objects</ a > ,
3730
3628
< ol >
3731
3629
< li >
3732
- [= list/For each =] |record:NDEFRecord| in |message:NDEFMessage|,
3733
- < ol >
3734
- < li >
3735
- Let |matched:boolean| be `false`.
3736
- </ li >
3737
- < li >
3738
- If |reader|.< a > [[\Id]]</ a > is not `undefined` and is not equal
3739
- to |record|'s < a href ="#dom-ndefrecord-id "> id</ a > ,
3740
- [= iteration/continue =].
3741
- If it is equal, set |matched| to `true`.
3742
- </ li >
3743
- < li >
3744
- If |reader|.< a > [[\RecordType]]</ a > is not `undefined` and is
3745
- not equal to |record|'s
3746
- < a href ="#dom-ndefrecord-recordtype "> recordType</ a > ,
3747
- [= iteration/continue =].
3748
- If it is equal, set |matched| to `true`.
3749
- </ li >
3750
- < li >
3751
- If |reader|.< a > [[\MediaType]]</ a > is not `undefined` and is not
3752
- equal to
3753
- |record|'s < a href ="#dom-ndefrecord-mediatype "> mediaType</ a > ,
3754
- [= iteration/continue =].
3755
- If it is equal, set |matched| to `true`.
3756
- </ li >
3757
- < li >
3758
- If |matched| is `true`,
3759
- < ol >
3760
- < li >
3761
- < a > fire an event</ a > named "`reading`"
3762
- at |reader| using < a > NDEFReadingEvent</ a > with its
3763
- < a > serialNumber</ a > attribute initialized to |serialNumber|
3764
- and < a > message</ a > attribute initialized to |message|.
3765
- </ li >
3766
- < li >
3767
- [= iteration/Break =].
3768
- </ li >
3769
- </ ol >
3770
- </ li >
3771
- </ ol >
3630
+ < a > fire an event</ a > named "`reading`" at |reader| using
3631
+ < a > NDEFReadingEvent</ a > with its < a > serialNumber</ a > attribute
3632
+ initialized to |serialNumber| and < a > message</ a > attribute
3633
+ initialized to |message|.
3772
3634
</ li >
3773
3635
</ ol >
3774
3636
</ li >
0 commit comments