UNPKG

nats.ws

Version:
43 lines (39 loc) 1.16 kB
<!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, StringCodec } from '../nats.mjs' // 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>