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

unmute

v0.1.3

Published

start/stop web audio

Downloads

88

Readme

Build Status

Unmute adds a mute/unmute button to the top right corner of your page.

This button implements many browsers' requirements that the AudioContext is started by a user action before it can play any sound. If the AudioContext is not running when the page is loaded, the button will initially be muted until a user clicks to unmute the button.

example

INSTALLATION

npm install unmute

USAGE

The mute button can be added to the page like so:

UnmuteButton()

es6

import UnmuteButton from 'unmute'

UnmuteButton()

HTML

If your code uses Tone.js, you can simply add the following code to your <head> and it'll add an UnmuteButton to the page and bind itself to Tone.js' AudioContext. Tone.js must be included on the page.

<script src="https://unpkg.com/unmute" data-add-button="true"></script>

API

Parameter

UnmuteButton takes an optional object as a parameter.

UnmuteButton({
	//the parent element of the mute button
	//can pass in "none" to create the element, but not add it to the DOM
	container : document.querySelector('#container'),
	//the title which appears on the iOS lock screen
	title : 'Web Audio',
	//force it to start muted, even when the AudioContext is running
	mute : false
	//AudioContext
	context : new AudioContext(),
})

container

The HTMLElement which the button will be added to

title

UnmuteButton also unmutes the browser tab on iOS even when the mute toggle rocker switch is toggled on. This causes a title to appear on the phone's lock screen. The default title says "Web Audio"

mute

This will force the initial state of the button to be muted. Though, you cannot force it to be 'unmuted' by passing in {'mute' : false} because the default state of the button is also determined by the state of the AudioContext.

context

If a context is passed in, it will be wrapped and available as a property of the returned object. If no context was passed in, one will be created. You can access the created context as a property.

const { context } = UnmuteButton()

Events

UnmuteButton returns an event emitting object.

'start'

Emitted when the AudioContext is started for the first time.

UnmuteButton().on('start', () => {
	//AudioContext.state is 'running'
})

'mute'

Emitted when the AudioContext is muted.

'unmute'

Emitted when the AudioContext is unmuted.

Methods

remove()

Removes the button element from its container

const unmute = UnmuteButton()
//remove the element
unmute.remove()

Style

The UnmuteButton's default styling can be overwritten with css. The UnmuteButton is a <button> element with id #unmute-button. When in a muted state, a class .muted is added to the element.

iOS

Additionally this button plays a silent sound through an <audio> element when the button is clicked which enables sound on iOS even when the mute rocker switch is toggled on. [reference]

Earlier versions of Tone.js (before [email protected])

If using an older version of Tone with a global reference to Tone.js, it should work as with the above examples. The one exception is if you're using it with a build system which does not create a reference to Tone on the window.

This has been tested with Tone.js (>[email protected])

import Tone from 'tone'

UnmuteButton({ tone : Tone })

Without Tone.js

To use it without Tone.js, check out this example. Be sure to use the wrapped and shimmed AudioContext instance which is a property of the UnmuteButton instance. Automatically adding the button to the body (using data-add-button="true") will not work.