Ravenstine / airsocket

Send/receive messages through an audio signal.
MIT License
17 stars 2 forks source link

AirSocket

Transmit messages through an audio signal using frequency modulation.

Messages

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.

Installation

npm install --save airsocket

Use

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. ;)

Options

Try It Out

See it in action!

Notes

The protocol being used is subject to change!

Also, tests are broken.