npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

airsocket

v0.0.7

Published

Transmit/receive messages through audio.

Downloads

26

Readme

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.