Skip to content

Commit

Permalink
Released: MultiStreamsMixer v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Sep 27, 2017
1 parent bb316ce commit fa2f621
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 42 deletions.
35 changes: 24 additions & 11 deletions MultiStreamsMixer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Last time updated: 2017-09-04 2:21:39 PM UTC
// Last time updated: 2017-09-27 9:40:20 AM UTC

// ________________________
// MultiStreamsMixer v1.0.3
// MultiStreamsMixer v1.0.4

// Open-Sourced: https://github.com/muaz-khan/MultiStreamsMixer

Expand Down Expand Up @@ -125,6 +125,23 @@ function MultiStreamsMixer(arrayOfMediaStreams) {
Storage.AudioContext = webkitAudioContext;
}

function setSrcObject(stream, element, ignoreCreateObjectURL) {
if ('createObjectURL' in URL && !ignoreCreateObjectURL) {
try {
element.src = URL.createObjectURL(stream);
} catch (e) {
setSrcObject(stream, element, true);
return;
}
} else if ('srcObject' in element) {
element.srcObject = stream;
} else if ('mozSrcObject' in element) {
element.mozSrcObject = stream;
} else {
alert('createObjectURL/srcObject both are not supported.');
}
}

this.startDrawingFrames = function() {
drawVideosToCanvas();
};
Expand Down Expand Up @@ -157,16 +174,16 @@ function MultiStreamsMixer(arrayOfMediaStreams) {
canvas.width = videosLength > 1 ? remaining[0].width * 2 : remaining[0].width;

var height = 1;
if (videosLength == 3 || videosLength == 4) {
if (videosLength === 3 || videosLength === 4) {
height = 2;
}
if (videosLength == 5 || videosLength == 6) {
if (videosLength === 5 || videosLength === 6) {
height = 3;
}
if (videosLength == 7 || videosLength == 8) {
if (videosLength === 7 || videosLength === 8) {
height = 4;
}
if (videosLength == 9 || videosLength == 10) {
if (videosLength === 9 || videosLength === 10) {
height = 5;
}
canvas.height = remaining[0].height * height;
Expand Down Expand Up @@ -342,11 +359,7 @@ function MultiStreamsMixer(arrayOfMediaStreams) {
function getVideo(stream) {
var video = document.createElement('video');

if ('srcObject' in video) {
video.srcObject = stream;
} else {
video.src = URL.createObjectURL(stream);
}
setSrcObject(stream, video);

video.muted = true;
video.volume = 0;
Expand Down
6 changes: 3 additions & 3 deletions MultiStreamsMixer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Or link specific build:
* https://github.com/muaz-khan/MultiStreamsMixer/releases

```html
<script src="https://github.com/muaz-khan/MultiStreamsMixer/releases/download/1.0.3/MultiStreamsMixer.js"></script>
<script src="https://github.com/muaz-khan/MultiStreamsMixer/releases/download/1.0.4/MultiStreamsMixer.js"></script>
```

# How to mix audios?
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "multistreamsmixer",
"description": "Pass multiple streams (e.g. screen+camera or multiple-cameras) and get single stream.",
"version": "1.0.3",
"version": "1.0.4",
"authors": [
{
"name": "Muaz Khan",
Expand Down
17 changes: 17 additions & 0 deletions dev/cross-browser-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ if (typeof AudioContext !== 'undefined') {
} else if (typeof webkitAudioContext !== 'undefined') {
Storage.AudioContext = webkitAudioContext;
}

function setSrcObject(stream, element, ignoreCreateObjectURL) {
if ('createObjectURL' in URL && !ignoreCreateObjectURL) {
try {
element.src = URL.createObjectURL(stream);
} catch (e) {
setSrcObject(stream, element, true);
return;
}
} else if ('srcObject' in element) {
element.srcObject = stream;
} else if ('mozSrcObject' in element) {
element.mozSrcObject = stream;
} else {
alert('createObjectURL/srcObject both are not supported.');
}
}
8 changes: 4 additions & 4 deletions dev/draw-videos-on-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ function drawVideosToCanvas() {
canvas.width = videosLength > 1 ? remaining[0].width * 2 : remaining[0].width;

var height = 1;
if (videosLength == 3 || videosLength == 4) {
if (videosLength === 3 || videosLength === 4) {
height = 2;
}
if (videosLength == 5 || videosLength == 6) {
if (videosLength === 5 || videosLength === 6) {
height = 3;
}
if (videosLength == 7 || videosLength == 8) {
if (videosLength === 7 || videosLength === 8) {
height = 4;
}
if (videosLength == 9 || videosLength == 10) {
if (videosLength === 9 || videosLength === 10) {
height = 5;
}
canvas.height = remaining[0].height * height;
Expand Down
6 changes: 1 addition & 5 deletions dev/get-video-element.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
function getVideo(stream) {
var video = document.createElement('video');

if ('srcObject' in video) {
video.srcObject = stream;
} else {
video.src = URL.createObjectURL(stream);
}
setSrcObject(stream, video);

video.muted = true;
video.volume = 0;
Expand Down
Loading

0 comments on commit fa2f621

Please sign in to comment.