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

media-source-stream

v2.0.4

Published

Create a MediaSource from a Readable stream

Downloads

33

Readme

media-source-stream

Deprecated: Use feross/mediasource

Creates MSE MediaSource objects from readable streams.

Does the reverse of media-recorder-stream.

Demo

npm install media-source-stream

Usage

The easiest way to get a compatible readable stream is to use media-recorder-stream, but you can also create your own via FFMPEG.

var getMedia = require('getusermedia')
var MediaRecorderStream = require('media-recorder-stream')
var MediaSourceStream = require('media-source-stream')

getMedia({video: true, audio: true}, function (err, media) {

  // Change a MediaStream into a data stream
  var recordStream = MediaRecorderStream(media, {
    mimeType: 'video/webm; codecs="opus,vp8"', // You MUST set the MIME type
    interval: 100 // A short interval is recommended to keep buffer sizes low
  })
  
  // Do stuff to the data...
  
  // And change it back!
  var sourceStream = MediaSourceStream({  // Creates a writable stream
    mimeType: 'video/webm; codecs="opus,vp8"'
  }) 
  recordStream.pipe(sourceStream)
  sourceStream.mediaSource
})

Why?

  • Modify MediaStreams in realtime, in the browser.
  • Send audio/video data over a WebRTC DataChannel.
  • Send audio/video over a net.socket.
  • Upload media without needing to finish recording.

API

sourceStream = new MediaSourceStream([opts])

Create a new MediaSourceStream, which is a writable stream.

Optional opts is the options object to pass to the MediaSource constructor.

sourceStream.mediaSource

The output MediaSource object.

Example

Here is an example of how to send video/audio over a WebRTC DataChannel (with simple-peer), without using media channels. You could also do this over WebSockets.

Keep in mind there is a moderate increase in latency, so this is only suitable when MediaStreams aren't an option.

getMedia({video: true, audio: true}, function (err, stream) {
  var recordStream = MediaRecorderStream(stream, {
    mimeType: 'video/webm; codecs=vp8',
    interval: 100
  })

  var peer1 = new SimplePeer({
    initiator: true
  })
  var peer2 = new SimplePeer()
  peer1.on('signal', function (data) {
    peer2.signal(data)
  })
  peer2.on('signal', function (data) {
    peer1.signal(data)
  })

  peer1.on('connect', function () {
    recordStream.pipe(peer1)
  })

  var sourceStream = MediaSourceStream()
  peer2.pipe(sourceStream)

  var url = window.URL.createObjectURL(sourceStream.mediaSource)
  document.querySelector('video').src = url
})

Note: You want to start recording once you already have a connection so that all recorded data is sent. If any initial data is missing, the stream cannot be reconstructed on the other side.