@@ -1065,15 +1065,17 @@ <h4>
1065
1065
< section > < h3 > Save and restore game progress with an NFC tag</ h3 >
1066
1066
< p >
1067
1067
Filtering of relevant data sources can be done by the use of
1068
- the < a > NDEFScanOptions</ a > . Below we use the custom record identifier
1069
- "`my-game-progress`" as a relative URL so that when we read the data, we
1070
- immediately update the game progress by issuing a write with a custom NDEF
1071
- data layout.
1068
+ a custom record identifier, in this case "`my-game-progress`".
1069
+ When we read the data, we immediately update the game progress by issuing
1070
+ a write with a custom NDEF data layout.
1072
1071
</ p >
1073
1072
< pre class ="example ">
1074
1073
const reader = new NDEFReader();
1075
- await reader.scan({ id: "my-game-progress" } );
1074
+ await reader.scan();
1076
1075
reader.onreading = async event => {
1076
+ if (event.message.id !== "my-game-progress")
1077
+ return;
1078
+
1077
1079
console.log(`Game state: ${ JSON.stringify(event.message.records) }`);
1078
1080
1079
1081
const encoder = new TextEncoder();
@@ -1102,9 +1104,7 @@ <h4>
1102
1104
</ p >
1103
1105
< pre class ="example ">
1104
1106
const reader = new NDEFReader();
1105
- await reader.scan({
1106
- mediaType: "application/*json"
1107
- });
1107
+ await reader.scan();
1108
1108
reader.onreading = event => {
1109
1109
const decoder = new TextDecoder();
1110
1110
for (const record of event.message.records) {
@@ -1259,7 +1259,7 @@ <h4>
1259
1259
</ p >
1260
1260
< pre class ="example ">
1261
1261
const reader = new NDEFReader();
1262
- await reader.scan({ recordType: "example.com:smart-poster" } );
1262
+ await reader.scan();
1263
1263
reader.onreading = event => {
1264
1264
const externalRecord = event.message.records.find(
1265
1265
record => record.type == "example.com:smart-poster"
@@ -1352,10 +1352,11 @@ <h4>
1352
1352
</ pre >
1353
1353
< pre class ="example ">
1354
1354
const reader = new NDEFReader();
1355
- await reader.scan({ recordType: "example.com:shoppingItem" } );
1355
+ await reader.scan();
1356
1356
reader.onreading = event => {
1357
1357
const shoppingItemRecord = event.message.records[0];
1358
- if (!shoppingItemRecord) {
1358
+ if (!shoppingItemRecord ||
1359
+ shoppingItemRecord.recordType !== "example.com:shoppingItem") {
1359
1360
return;
1360
1361
}
1361
1362
@@ -1913,27 +1914,6 @@ <h2>The <dfn>record type</dfn> string</h2>
1913
1914
</ tr >
1914
1915
</ thead >
1915
1916
< tbody data-link-for ="NDEFScanOptions ">
1916
- < tr >
1917
- < td > < dfn > [[\Id]]</ dfn > </ td >
1918
- < td > `undefined`</ td >
1919
- < td >
1920
- The {{NDEFScanOptions}}.< a > id</ a > value.
1921
- </ td >
1922
- </ tr >
1923
- < tr >
1924
- < td > < dfn > [[\RecordType]]</ dfn > </ td >
1925
- < td > `undefined`</ td >
1926
- < td >
1927
- The {{NDEFScanOptions}}.< a > recordType</ a > value.
1928
- </ td >
1929
- </ tr >
1930
- < tr >
1931
- < td > < dfn > [[\MediaType]]</ dfn > </ td >
1932
- < td > `undefined`</ td >
1933
- < td >
1934
- The {{NDEFScanOptions}}.< a > mediaType</ a > value.
1935
- </ td >
1936
- </ tr >
1937
1917
< tr >
1938
1918
< td > < dfn > [[\Signal]]</ dfn > </ td >
1939
1919
< td > `undefined`</ td >
@@ -1944,13 +1924,6 @@ <h2>The <dfn>record type</dfn> string</h2>
1944
1924
</ tbody >
1945
1925
</ table >
1946
1926
1947
- < p class ="note ">
1948
- Note that the internal slots of {{NDEFReader}} come from the
1949
- |options:NDEFScanOptions| passed to < a > NDEFReader.scan()</ a > .
1950
- Therefore there is maximum one filter associated with any given
1951
- {{NDEFReader}} object and successive invocations of < a > NDEFReader.scan()</ a >
1952
- with new |options:NDEFScanOptions| will replace existing filters.
1953
- </ p >
1954
1927
< p >
1955
1928
The < dfn data-dfn-for ="NDEFReader "> onreading</ dfn > is an {{EventHandler}}
1956
1929
which is called to notify that new reading is available.
@@ -2191,60 +2164,18 @@ <h3>The <dfn>NDEFWriteOptions</dfn> dictionary</h3>
2191
2164
< section data-dfn-for ="NDEFScanOptions ">
2192
2165
< h3 > The < dfn > NDEFScanOptions</ dfn > dictionary</ h3 >
2193
2166
< p >
2194
- To describe which messages an application is interested in , the
2167
+ To pass an [= AbortSignal/aborted flag =] , the
2195
2168
< a > NDEFScanOptions</ a > dictionary is used:
2196
2169
</ p >
2197
2170
< pre class ="idl ">
2198
2171
dictionary NDEFScanOptions {
2199
- USVString id;
2200
- USVString recordType;
2201
- USVString mediaType;
2202
2172
AbortSignal? signal;
2203
2173
};
2204
2174
</ pre >
2205
2175
< p >
2206
2176
The < dfn > signal</ dfn > property allows to abort the
2207
2177
[=NDEFReader/scan()=] operation.
2208
2178
</ p >
2209
- < p >
2210
- The < dfn > id</ dfn > property
2211
- denotes the string value which is used for matching the
2212
- < a > record identifier</ a > of each
2213
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2214
- If the dictionary member is not present,
2215
- then it will be ignored by the
2216
- < a href ="#steps-listen "> NFC listen algorithm</ a > .
2217
- </ p >
2218
- < p >
2219
- The < dfn > recordType</ dfn > property
2220
- denotes the string value which is used for matching the
2221
- < a > record type</ a > of each
2222
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2223
- If the dictionary member is not present,
2224
- then it will be ignored by the
2225
- < a href ="#steps-listen "> NFC listen algorithm</ a > .
2226
- </ p >
2227
- < p >
2228
- The < dfn > mediaType</ dfn > property
2229
- denotes the < a > match pattern</ a > which is used for matching the
2230
- [=NDEFRecord/mediaType=] property of each
2231
- < a > NDEFRecord</ a > object in an < a > NDEF message</ a > .
2232
- </ p >
2233
- < pre
2234
- title ="Filter accepting only JSON content "
2235
- class ="example highlight ">
2236
- const options = {
2237
- mediaType: "application/*json" // any JSON-based MIME type
2238
- }
2239
- </ pre >
2240
- < pre
2241
- title ="Filter which only accepts binary content for a custom record identifier "
2242
- class ="example highlight ">
2243
- const options = {
2244
- id: "my-restaurant-daily-menu",
2245
- mediaType: "application/octet-stream"
2246
- }
2247
- </ pre >
2248
2179
</ section > <!-- NDEFScanOptions -->
2249
2180
2250
2181
< section id ="writing-content ">
@@ -3349,28 +3280,6 @@ <h3><dfn>Writing content</dfn></h3>
3349
3280
then the < a > UA</ a > MUST listen to < a > NDEF message</ a > s on all connected
3350
3281
NFC adapters.
3351
3282
</ p >
3352
- < p >
3353
- Each {{NDEFReader}} can accept < a > NDEF message</ a > s based on
3354
- data type, and record identifier filters.
3355
- </ p >
3356
-
3357
- < section > < h3 > Match patterns</ h3 >
3358
- < div >
3359
- A < dfn > match pattern</ dfn > is defined by the following ABNF:
3360
- < pre class ="abnf ">
3361
- match-pattern = top-level-type "/" [ tree "." ] subtype [ "+" suffix ] [ ";" parameters ]
3362
- top-level-type = "*" / < VCHAR except "/" and "*" >
3363
- subtype = "*" / < VCHAR except "+" >
3364
- </ pre >
3365
- A < a > match pattern</ a > is a
3366
- < a href ="http://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html#tag_02_13_03 ">
3367
- glob</ a > used for matching < a > MIME type</ a > s,
3368
- for instance the pattern "`application/*+json`" matches
3369
- "`application/calendar+json`", but does not match
3370
- "`application/json`". The pattern
3371
- "`*/*json`", on the other hand, matches both.
3372
- </ div >
3373
- </ section >
3374
3283
3375
3284
< section > < h3 > The < strong > scan()</ strong > method</ h3 >
3376
3285
< p >
@@ -3397,18 +3306,6 @@ <h3><dfn>Writing content</dfn></h3>
3397
3306
If |key| equals "`signal`" and |value| is not `undefined`, set
3398
3307
|reader|.< a > [[\Signal]]</ a > to |value|.
3399
3308
</ li >
3400
- < li >
3401
- Otherwise, if |key| equals "`id`", set
3402
- |reader|.< a > [[\Id]]</ a > to |value|.
3403
- </ li >
3404
- < li >
3405
- Otherwise, if |key| equals "`recordType`", set
3406
- |reader|.< a > [[\RecordType]]</ a > to |value|.
3407
- </ li >
3408
- < li >
3409
- Otherwise, if |key| equals "`mediaType`", set
3410
- |reader|.< a > [[\MediaType]]</ a > to |value|.
3411
- </ li >
3412
3309
</ ol >
3413
3310
</ li >
3414
3311
< li >
@@ -3556,49 +3453,13 @@ <h3><dfn>Writing content</dfn></h3>
3556
3453
< ol class =algorithm >
3557
3454
< li >
3558
3455
[= list/For each =] {{NDEFReader}} instance |reader:NDEFReader| in
3559
- the < a > activated reader objects</ a > , run the following sub-steps:
3456
+ the < a > activated reader objects</ a > ,
3560
3457
< ol >
3561
3458
< li >
3562
- [= list/For each =] |record:NDEFRecord| in |message:NDEFMessage|,
3563
- < ol >
3564
- < li >
3565
- Let |matched:boolean| be `false`.
3566
- </ li >
3567
- < li >
3568
- If |reader|.< a > [[\Id]]</ a > is not `undefined` and is not equal
3569
- to |record|'s < a href ="#dom-ndefrecord-id "> id</ a > ,
3570
- [= iteration/continue =].
3571
- If it is equal, set |matched| to `true`.
3572
- </ li >
3573
- < li >
3574
- If |reader|.< a > [[\RecordType]]</ a > is not `undefined` and is
3575
- not equal to |record|'s
3576
- < a href ="#dom-ndefrecord-recordtype "> recordType</ a > ,
3577
- [= iteration/continue =].
3578
- If it is equal, set |matched| to `true`.
3579
- </ li >
3580
- < li >
3581
- If |reader|.< a > [[\MediaType]]</ a > is not `undefined` and is not
3582
- equal to
3583
- |record|'s < a href ="#dom-ndefrecord-mediatype "> mediaType</ a > ,
3584
- [= iteration/continue =].
3585
- If it is equal, set |matched| to `true`.
3586
- </ li >
3587
- < li >
3588
- If |matched| is `true`,
3589
- < ol >
3590
- < li >
3591
- < a > fire an event</ a > named "`reading`"
3592
- at |reader| using < a > NDEFReadingEvent</ a > with its
3593
- < a > serialNumber</ a > attribute initialized to |serialNumber|
3594
- and < a > message</ a > attribute initialized to |message|.
3595
- </ li >
3596
- < li >
3597
- [= iteration/Break =].
3598
- </ li >
3599
- </ ol >
3600
- </ li >
3601
- </ ol >
3459
+ < a > fire an event</ a > named "`reading`" at |reader| using
3460
+ < a > NDEFReadingEvent</ a > with its < a > serialNumber</ a > attribute
3461
+ initialized to |serialNumber| and < a > message</ a > attribute
3462
+ initialized to |message|.
3602
3463
</ li >
3603
3464
</ ol >
3604
3465
</ li >
0 commit comments