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

fake-mediastreamtrack

v1.2.0

Published

Fake W3C MediaStreamTrack implementation

Downloads

124,340

Readme

fake-mediastreamtrack

Fake W3C MediaStreamTrack implementation. Suitable for for Node.js or testing.

This library is intended for Node.js applications or libraries that depend on the MediaStreamTrack class. The exposed FakeMediaStreamTrack class does not internally manage any audio/video source.

This library provides TypeScript definitions and the FakeMediaStreamTrack extendes the MediaStreamTrack interface, so it can be safely used in any code requiring a MediaStreamTrack object.

Install

$ npm install fake-mediastreamtrack

Usage

const { FakeMediaStreamTrack } = require('fake-mediastreamtrack');
// or
import { FakeMediaStreamTrack } from 'fake-mediastreamtrack';

const track = new FakeMediaStreamTrack({ kind: 'audio' });

track.enabled = false;

console.log(
  'track.readyState: %s, track.enabled: %s', track.readyState, track.enabled
);
// => 'track.readyState: live, track.enabled: false'

const clonedTrack = track.clone();

track.stop();

console.log('track.readyState: %s', track.readyState);
// => 'track.readyState: ended'

console.log('clonedTrack.readyState: %s', clonedTrack.readyState);
// => 'clonedTrack.readyState: live'

clonedTrack.applyConstraints({ frameRate: { max: 30, ideal: 20 } });

console.log('clonedTrack.getConstraints(): %o', clonedTrack.getConstraints());
// => clonedTrack.getConstraints(): { frameRate: { max: 30, ideal: 20 } }

API additions

Constructor

The FakeMediaStreamTrack class constructor accepts an object with the following fields.

const track = new FakeMediaStreamTrack({ kind, id, label, isolated, muted, data })
  • kind (string, mandatory): "audio" or "video".
  • id (string, optional): Track unique identificator. If not given, a random one is generated.
  • label (string, optional): Track label. Defaults to empty string.
  • isolated (boolean, optional): See the spec. Defaults to false.
  • muted (boolean, optional): Whether this track belongs to a muted source. Defaults to false.
  • data (object, options): An object with custom application data.

Custom setters and getters

  • track.data getter returns custom application data object. The app can write into it at any time.
  • track.enabled = flag setter fires a proprietary "@enabledchange" event if the enabled property changed.

Custom methods and additions

  • track.stop() will fire a proprietary "@stop" event if not already stopped.
  • track.remoteStop() emulates a stop generated remotely. It will fired a proprietary "@stop" event and "ended" event if not already stopped.
  • track.remoteMute() emulates a mute generated remotely. It will fired "mute" event if not already muted.
  • track.remoteUnmute() emulates a unmute generated remotely. It will fired "unmute" event if not already unmuted.
const { FakeMediaStreamTrack } = require('fake-mediastreamtrack');
const track = new FakeMediaStreamTrack({ kind: 'video' });

track.onended = () => console.log('track ended (1)');
track.addEventListener('ended', () => console.log('track ended (2)'));

track.addEventListener('@enabledchange', () => {
  console.log('track enabled changed:', track.enabled);
});

track.enabled = false;
track.enabled = false;
track.enabled = true;
track.remoteStop();

// => track enabled changed: false
// => track enabled changed: true
// => track ended (1)
// => track ended (2)

Limitations

Some W3C MediaStreamTrack properties and methods are not implemented:

  • track.getCapabilities()
  • track.getSettings()
  • track.onisolationchange
  • track.onoverconstrained

Author

License

ISC