Skip to content

Instantly share code, notes, and snippets.

@mkozjak
Last active April 7, 2021 08:34
Show Gist options
  • Save mkozjak/fa9296484c40445af516e563c65536bf to your computer and use it in GitHub Desktop.
Save mkozjak/fa9296484c40445af516e563c65536bf to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="./lib/rpcwebsockets.js"></script>
<script type="text/javascript">
function myFunction() {
var ws = new RPCWebSocket("ws://127.0.0.1:3333")
ws.once("open", function() {
console.log("socket opened")
ws.call("sum", [ 5, 3 ])
.then(function(resp) {
alert("server response: " + resp)
ws.close()
})
})
ws.once("close", function() {
console.log("socket closed")
})
}
</script>
</head>
<body>
<h1>rpc-websockets browser test</h1>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
@sagittaracc
Copy link

there is no rpcwebsockets.js in the lib directory
when I include index.browser-bundle.js and go for new RPCWebSocket it says RPCWebSocket is not a constructor thumb down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment