-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
67 lines (53 loc) · 1.85 KB
/
demo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <script src="https://cdn.jsdelivr.net/gh/magiclen/tw-nhi-icc/dist/tw-nhi-icc.min.js"></script> -->
<script src="./dist/tw-nhi-icc.min.js"></script>
<title>TW NHI IC Card</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
#ta {
height: auto;
font-family: monospace, monospace;
}
</style>
</head>
<body class="p-3 p-lg-5">
<div class="form-floating">
<textarea id="ta" class="form-control" rows="15" readonly></textarea>
<label id="tal" for="ta">與 TW NHI IC Card Service 建立連線中……</label>
</div>
<script>
const tal = document.getElementById("tal");
const ta = document.getElementById("ta");
const sleep = (milliseconds) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};
const init = async () => {
const service = new TWNHIICCService();
for(;;) {
try {
await service.openWebSocket();
break;
} catch (error) {
await sleep(1000);
continue;
}
}
service.onWebSocketUpdate = (cards) => {
ta.innerHTML = JSON.stringify(cards, null, 4);
tal.innerHTML = "健保卡清單";
};
service.onWebSocketRetry = () => {
ta.innerHTML = "";
tal.innerHTML = "與 TW NHI IC Card Service 重新連線中";
};
};
init().catch(error => {
console.error(error);
});
</script>
</body>
</html>