This demo connects to a live Bugout server using its public address and then runs the "ping" function on that server and displays the result in the log below.
You can also run a copy of the Bugout server in your own browser tab to try it out locally on your machine.
// connect to server using its public address
var b = new Bugout(window.location.hash.substr(1) || "bUH7ukDvd9R2xLLRKMKWZ1mGPkgdVfufye");
log("My address is " + b.address())();
log("Connecting to the server...\n(this can take a minute)")();
// wait for connection to the server
b.on("server", function() {
// ok, we're connected
log("Connected to the server.")();
// make an RPC API call on the server and log the result
b.rpc("ping", {"Hello": "world"}, log("response:"));
// watch for {"Hello": "world", "pong": true} in the log below
// show a simple UI for testing the server API
showUI();
});
// also watch for other peers joining this server's swarm
b.on("seen", log("seen:"));