-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
48 lines (41 loc) · 1.25 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
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="origin-trial"
content="_____"/>
</head>
<script>
async function connect() {
const url = 'quic-transport://example.com:4433/quictransport_example';
const transport = new QuicTransport(url);
transport.closed.then(() => {
console.log(`connection closed`);
}).catch((error) => {
console.error(`connection closed due to ${error}`);
});
await transport.ready;
const reader = transport.receiveDatagrams().getReader();
const writer = transport.sendDatagrams().getWriter();
while (true) {
console.log("wait read");
const res = await reader.read();
if (res.done) {
break;
}
const dataView = new DataView(res.value.buffer);
const value = dataView.getUint8(0);
console.log("receive dgram " + value);
if (value > 0) {
await writer.write(new Uint8Array([value - 1]));
} else {
transport.close();
break;
}
}
}
</script>
<body>
<button onclick="connect();">connect</button>
</body>
</html>