Giter Club home page Giter Club logo

airsocket's Introduction

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

  • audioSource: This is an object passed into your callback function from 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.
  • worker: Runs the decoding logic in a WebWorker, which results in better performance on devices because processing won't be happening on the main thread. By default, it's set to true. You can set it to false and everything should work as expected, but there could be a performance decrease as a result. On newer browsers, it is best to leave true.
  • bitDuration: The number of milliseconds spent per-bit. The larger the number, the longer it takes to transmit a single message. Making this number larger increases accuracy.
  • messageLength: The maximum number of bytes that a message will support. By default, this number is 12(just enough for 'hello world!').
  • formats: Expects a list of strings to signify different "formats" to match. By default, it is set to ['ascii'] because that has a little better fault-tolerance than 'string', though it also supports string, binary, base64, md5, and sha1.
  • transmit: If set to true, the AirSocket will only send messages but not listen.
  • receive: If set to true, the AirSocket will listen for messages but not send any.
  • frequencies: Expects an object that holds values that override the default frequencies that represent binary numbers.
    • mark: The frequency that carries the '1' bit.
    • space: The frequency that carries the '0' bit.
  • processor: Add a custom script processor. Normally, one gets created automatically from a passed-in AudioContext but, if you need to use the processor directly, you can create one from a context and pass it in here.

Try It Out

See it in action!

Notes

The protocol being used is subject to change!

Also, tests are broken.

airsocket's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.