-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Update index.js #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Update index.js #775
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,39 @@ | ||
| scanButton.addEventListener("click", async () => { | ||
| scanButton.addEventListener("click", async () => { | ||
| log("User clicked scan button"); | ||
|
|
||
| try { | ||
| const ndef = new NDEFReader(); | ||
| await ndef.scan(); | ||
| log("> Scan started"); | ||
|
|
||
| ndef.addEventListener("readingerror", () => { | ||
| log("Argh! Cannot read data from the NFC tag. Try another one?"); | ||
| }); | ||
|
|
||
| ndef.addEventListener("reading", ({ message, serialNumber }) => { | ||
| log(`> Serial Number: ${serialNumber}`); | ||
| log(`> Records: (${message.records.length})`); | ||
| }); | ||
| } catch (error) { | ||
| log(`> Records: (${message.records.length})`); | ||
| for (const record of message.records) { | ||
| log(`\nRecord id: ${record.id}`); | ||
| log(`Record type: ${record.recordType}`); | ||
| log(`MIME type: ${record.mediaType}`); | ||
| switch (record.recordType) { | ||
| case "text": | ||
| { | ||
| const textDecoder = new TextDecoder(record.encoding); | ||
| log(`Text: ${textDecoder.decode(record.data)} (${record.lang})`); | ||
| } | ||
| break; | ||
| case "url": | ||
| { | ||
| const textDecoder = new TextDecoder(); | ||
| log(`URL: ${textDecoder.decode(record.data)}`); | ||
| } | ||
| break; | ||
| default: | ||
| // TODO: Handle other records with record data. | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we have a spacer to make it clear there are multiple records?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good idea. I want to further parse other types of tags as well. is this fine?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I'd parse more types in a sample like this. |
||
| } catch (error) { | ||
| log("Argh! " + error); | ||
| } | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.