testFlow/ui/page/nats/wss.html
Wyle.Gong-巩文昕 7a1aae1e2f ui
2025-04-23 11:21:08 +08:00

43 lines
1.1 KiB
HTML

<!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>