-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathwss.html
42 lines (39 loc) · 1.12 KB
/
wss.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
crossorigin="anonymous">
</head>
<body>
<!-- a place to record messages -->
<div id="messages" class="container"></div>
<!-- load a script -->
<script type="module">
import { connect } from '../nats.js'
// add an entry to the document
function addEntry(s) {
const p = document.createElement("pre");
p.appendChild(document.createTextNode(s));
document.getElementById("messages").appendChild(p);
}
const init = async function () {
try {
// create a connection to a wss server
const nc = await connect({ servers: 'wss://localhost:9222' });
addEntry('connected!');
await nc.flush();
addEntry('did a round-trip to the server');
// close the connection
await nc.close();
addEntry('closed the connection');
} catch(err) {
addEntry(`error connecting - did you setup a wss server? ${err}`);
console.error(err)
}
}
init();
</script>
</body>
</html>