# multistreamsmixer

> Pass multiple streams (e.g. screen+camera or multiple-cameras) and get single stream.

Latest version **1.2.2** (published 2019-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install multistreamsmixer
pnpm add multistreamsmixer
yarn add multistreamsmixer
bun add multistreamsmixer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2019-06-21 |
| First published | 2017-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 59.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 457 |
| Author | Muaz Khan |
| Maintainers | muaz-khan |
| Keywords | webrtc, multistreamsmixer, webrtc-library, library, javascript, rtcweb, webrtc-experiment, javascript-library, muaz, muaz-khan |

## Links

- npm: https://www.npmjs.com/package/multistreamsmixer
- Repository: https://github.com/muaz-khan/MultiStreamsMixer
- Homepage: https://www.webrtc-experiment.com/MultiStreamsMixer/
- Issues: https://github.com/muaz-khan/MultiStreamsMixer/issues
- npm.io page: https://npm.io/package/multistreamsmixer

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2019-06-21
- 1.2.1 — 2019-06-18
- 1.2.0 — 2019-06-15
- 1.0.9 — 2019-06-15
- 1.0.8 — 2019-02-20
- 1.0.7 — 2018-12-22
- 1.0.6 — 2018-10-26
- 1.0.5 — 2018-10-26
- 1.0.4 — 2017-09-27
- 1.0.3 — 2017-09-04
- 1.0.2 — 2017-08-31
- 1.0.1 — 2017-08-30
- 1.0.0 — 2017-08-04

## README

# [MultiStreamsMixer.js](https://github.com/muaz-khan/MultiStreamsMixer) | [LIVE DEMO](https://www.webrtc-experiment.com/MultiStreamsMixer/)

* Mix Multiple Cameras or Videos
* Mix Multiple Microphones or Audios (Mp3/Wav/Ogg)
* Mix Multiple Screens or Screen+Video
* Mix Canvas 2D Animation + Camera + Screen
* and **GET SINGLE STREAM!!**

[![npm](https://img.shields.io/npm/v/multistreamsmixer.svg)](https://npmjs.org/package/multistreamsmixer) [![downloads](https://img.shields.io/npm/dm/multistreamsmixer.svg)](https://npmjs.org/package/multistreamsmixer) [![Build Status: Linux](https://travis-ci.org/muaz-khan/MultiStreamsMixer.png?branch=master)](https://travis-ci.org/muaz-khan/MultiStreamsMixer)

# All Demos

1. **Main Demo:** https://www.webrtc-experiment.com/MultiStreamsMixer/
2. [Record Multiple Cameras](https://www.webrtc-experiment.com/RecordRTC/simple-demos/multi-cameras-recording.html)
3. [Record Camera+Screen](https://www.webrtc-experiment.com/RecordRTC/simple-demos/video-plus-screen-recording.html)

> Pass multiple streams (e.g. screen+camera or multiple-cameras) and get single stream. 

# Link the library

```html
<script src="https://www.webrtc-experiment.com/MultiStreamsMixer.js"></script>
```

Or link specific build:

* https://github.com/muaz-khan/MultiStreamsMixer/releases

Or install using NPM:

```sh
npm install multistreamsmixer
```

And import/require:

```javascript
const MultiStreamsMixer = require('multistreamsmixer');
import MultiStreamsMixer from 'multistreamsmixer';
```

# How to mix audios?

```javascript
const audioMixer = new MultiStreamsMixer([microphone1, microphone2]);

// record using MediaRecorder API
const recorder = new MediaRecorder(audioMixer.getMixedStream());

// or share using WebRTC
rtcPeerConnection.addStream(audioMixer.getMixedStream());
```

# How to mix screen+camera?

```javascript
screenStream.fullcanvas = true;
screenStream.width = screen.width; // or 3840
screenStream.height = screen.height; // or 2160 

cameraStream.width = parseInt((20 / 100) * screenStream.width);
cameraStream.height = parseInt((20 / 100) * screenStream.height);
cameraStream.top = screenStream.height - cameraStream.height;
cameraStream.left = screenStream.width - cameraStream.width;

const mixer = new MultiStreamsMixer([screenStream, cameraStream]);

rtcPeerConnection.addStream(mixer.getMixedStream());

mixer.frameInterval = 1;
mixer.startDrawingFrames();

btnStopStreams.onclick = function() {
    mixer.releaseStreams();
};

btnAppendNewStreams.onclick = function() {
    mixer.appendStreams([anotherStream]);
};

btnStopScreenSharing.onclick = function() {
    // replace all old streams with this one
    // it will replace only video tracks
    mixer.resetVideoStreams([cameraStreamOnly]);
};
```

# How to mix multiple cameras?

```javascript
const mixer = new MultiStreamsMixer([camera1, camera2]);

rtcPeerConnection.addStream(mixer.getMixedStream());

mixer.frameInterval = 1;
mixer.startDrawingFrames();
```

# API

1. `getMixedStream`: (function) returns mixed MediaStream object
2. `frameInterval`: (property) allows you set frame interval
3. `startDrawingFrames`: (function) start mixing video streams
4. `resetVideoStreams`: (function) replace all existing video streams with new ones
5. `releaseStreams`: (function) stop mixing streams
6. `appendStreams`: (function) append extra/new streams (anytime)

# TypeScript / Angular

```javascript
import { MultiStreamsMixer } from 'yourPath/MultiStreamsMixer';
let mixer = new MultiStreamsMixer([stream1,stream2]);
mixer.appendStreams(stream3);
let mixed = mixer.getMixedStream();
```

P.S: pollyfills are removed (except for `AudioContext`) use adapter instead.

# Access `<canvas>` or `<video>` using `querySelector`

```javascript
var canvas = document.querySelector('canvas.multi-streams-mixer');
var videos = document.querySelectorAll('video.multi-streams-mixer');

canvas.style.opacity = .1;
```

# API

```javascript
// default elementClass is "multi-streams-mixer"
var instance = new MultiStreamsMixer(arrayOfMediaStreams, elementClass);

MultiStreamsMixer.prototype = {
	// get readonly MediaStream
	getMixedStream: function() {},

	// add more streams
	appendStreams: function(arrayOfMediaStreams) {},

	// replace with set of your own streams
	resetVideoStreams: function(arrayOfMediaStreams) {},

	// clear all the data
	clearRecordedData: function() {}
};
````

## License

[MultiStreamsMixer.js](https://github.com/muaz-khan/MultiStreamsMixer) is released under [MIT licence](https://github.com/muaz-khan/MultiStreamsMixer/blob/master/LICENSE) . Copyright (c) [Muaz Khan](https://MuazKhan.com).

---
_Source: https://npm.io/package/multistreamsmixer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
