Skip to content

Instantly share code, notes, and snippets.

@neopunisher
Created May 29, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neopunisher/a0bdb7dd19ba112bda30e73a34f260da to your computer and use it in GitHub Desktop.
Save neopunisher/a0bdb7dd19ba112bda30e73a34f260da to your computer and use it in GitHub Desktop.
ultrasonicsoundcontrol
(function(url, inj) {
inj(url).then(function() {
var ALPHABET = '0123456789';
var MESSAGE = '314159';
var button = document.createElement('button');
document.body.appendChild(button)
button.addEventListener('click', onButton);
function onButton() {
ssocket = new sonicnet.Sender({alphabet: ALPHABET, charDuration: 0.2});
ssocket.send(MESSAGE);
}
// On some other machine:
sserver = new sonicnet.Receiver({alphabet: ALPHABET});
sserver.on('message', function(message) {
// message is '31415'. Do something with it.
console.log(message);
});
sserver.start();
})
})('https://wzrd.in/standalone/sonicnet@latest', (src, head = true) => new Promise(function(c, d) {
var a = document.createElement("script");
a.src = src;
a.type = "text/javascript";
a.onload = c;
a.onerror = d;
document[head ? 'head' : 'body'].appendChild(a)
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment