forked from manekinekko/puzzle-duo-nfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
41 lines (33 loc) · 1.06 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<button id="scanButton">Scan</button>
<button id="writeButton">Write</button>
<audio src="/meow.wav" id="meow"></audio>
<script>
scanButton.addEventListener("click", async () => {
console.log("User clicked scan button");
try {
const ndef = new NDEFReader();
await ndef.scan();
console.log("> Scan started");
ndef.addEventListener("readingerror", () => {
console.log("Argh! Cannot read data from the NFC tag. Try another one?");
});
ndef.addEventListener("reading", ({ message, serialNumber }) => {
console.log(`> Serial Number: ${serialNumber}`);
console.log(`> Records: (${message.records.length})`);
meow.play();
});
} catch (error) {
console.log("Argh! " + error);
}
});
writeButton.addEventListener("click", async () => {
console.log("User clicked write button");
try {
const ndef = new NDEFReader();
await ndef.write("Hello world!");
console.log("> Message written");
} catch (error) {
console.log("Argh! " + error);
}
});
</script>