Transmit messages through an audio signal using frequency modulation.
Each message has a preamble byte of 01010101(the letter U), a fixed-size payload, and a postamble checksum byte which is all the payload bytes XOR'd together.
The duration of audio that represents a bit can be variable, but is currently defaulted to 2.3 milliseconds. It may be feasible to achieve a much smaller number of samples per bit.
npm install --save airsocket
AirSocket comes with a browserified bundle, so you can include it in the browser with a script tag:
<script type='text/javascript' src='node_modules/airsocket/dist/browser/airsocket.js' />
You can also use it in Node.js, though you'll have to provide your own WebAudio substitute.
It can be used with or without WebAudio, but this is a typical use in a browser:
AirSocket = require('airsocket');
// you should polyfill getUserMedia
navigator.getUserMedia({ audio: true}, function(e){
var socket = new AirSocket({audioSource: e});
socket.on('message', function(m){
alert(m.data); // m is a MessageEvent, just like with WebSocket
});
socket.send('hello world!');
}, function(err){console.log(err)});
// NOTE: I'm using semicolons just to appease you. ;)
getUserMedia
that allows AirSocket to create an audio context to access your microphone and speaker. This is technically optional, as the encoder can return buffers, but it will not automatically have microphone access.['ascii']
because that has a little better fault-tolerance than 'string', though it also supports string, binary, base64, md5, and sha1.The protocol being used is subject to change!
Also, tests are broken.