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

mediastream-gain-controller

v0.0.4

Published

Helps to control microphone volume level.

Downloads

2

Readme

mediastream-gain-controller

What is this?

A tiny module for creating a gain/volume controller for the audio channels in a MediaStream.

It's useful for controlling the volume of your microphone input before it's sent accross a peer connection in a WebRTC call, for example.

Installing

npm install mediastream-gain-controller

This will install mediastream-gain-controller.js that is vanilla js sources and mediastream-gain-controller.min.js which is minified AMD module.

An example

var MicGainController = require('mediastream-gain-controller.min');
var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
var gainController, microphoneStream;

getUserMedia(function (err, stream) {
    gainController = new MicGainController(stream);
    microphoneStream = gainController.outputStream;
});

function mute() {
    // set gain to 0, effectively muting it
    gainController.setGain(0); // or gainController.off();
}

function unmute() {
    // to unmute call 
    gainController.on(); // equivalent to setGain(1)
}

// set gain to 20%
// gainController.setGain(.2);

If you use SipMl5 as sip client and want to mute/unmute microphone than you can use solution which is described here what means that you will have to implement a lot of tricky things and cases. And of course it is tightly coupled with SipMl stack. But you can use mediastream-gain-controller which allows you not to stick to any sip stack implementation and simply do next:

IMPORTANT

SipMl has a bug :) When you call getUserMedia explicitly or implicitly, browser asks you for microphone access permissions. If you open your web site over https, browser will ask your permissions only once. But if you open you web site over http, it will be asking your permissions every time you make or receive a call. In order to eliminate this annoying behaviour, SipMl provides an option (enable_media_stream_cache = true) which allows to cache getUserMedia results. Unfortunately this feature doesn't work (even in latest version (1.4.217)). To fix that you should apply small patch.

Open tsip_dialog_invite.js and do the following changes:

  • find tmedia_session_mgr.prototype.SetParamSession(o_msession_mgr.e_type, "cache-stream", this.get_stack().network.b_cache_stream),
  • repace it with tmedia_session_mgr.prototype.SetParamSession(o_msession_mgr.e_type, "cache-stream", this.get_stack().media.b_cache_stream),

You can do it even in minified sources. Find .network.b_cache_stream and replace it with .media.b_cache_stream. That's it!

// make sure you enabled simpl getUserMedia stream caching by setting enable_media_stream_cache = true in sipml options
// __o_jsep_stream_audio global var in which sipml stores stream from getUserMedia request
__o_jsep_stream_audio = microphoneStream; // or gainController.outputStream
mute(); // unmute();

With JsSip everything is the same.

// you just need to path microphoneStream to JsSip.UA.call method in options parameter
jssipClient.call(targer, {mediaStream: microphoneStream});
mute(); // unmute();

Methods

You can check for support by checking the support property of the an instance of gainController

  • .setGain(Float) - takes a number between 1 and 0
  • .getGain() - returns current setting
  • .off() - shortcut for turning mic off
  • .on() - shortcut for full gain

License

MIT