attachmediastream
Advanced tools
Comparing version 0.1.1 to 1.0.0
(function(e){if("function"==typeof bootstrap)bootstrap("attachmediastream",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeAttachmediastream=e}else"undefined"!=typeof window?window.attachmediastream=e():global.attachmediastream=e()})(function(){var define,ses,bootstrap,module,exports; | ||
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ | ||
module.exports = function (element, stream, play) { | ||
var autoPlay = (play === false) ? false : true; | ||
module.exports = function (stream, el, options) { | ||
var URL = window.URL; | ||
var opts = { | ||
autoplay: true, | ||
mirror: false, | ||
muted: false | ||
}; | ||
var element = el || document.createElement('video'); | ||
var item; | ||
if (autoPlay) element.autoplay = true; | ||
if (options) { | ||
for (item in options) { | ||
opts[item] = options[item]; | ||
} | ||
} | ||
// handle mozilla case | ||
if (window.mozGetUserMedia) { | ||
if (opts.autoplay) element.autoplay = 'autoplay'; | ||
if (opts.muted) element.muted = true; | ||
if (opts.mirror) { | ||
['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) { | ||
var styleName = prefix ? prefix + 'Transform' : 'transform'; | ||
element.style[styleName] = 'scaleX(-1)'; | ||
}); | ||
} | ||
// this first one should work most everywhere now | ||
// but we have a few fallbacks just in case. | ||
if (URL && URL.createObjectURL) { | ||
element.src = URL.createObjectURL(stream); | ||
} else if (element.srcObject) { | ||
element.srcObject = stream; | ||
} else if (element.mozSrcObject) { | ||
element.mozSrcObject = stream; | ||
if (autoPlay) element.play(); | ||
} else { | ||
if (typeof element.srcObject !== 'undefined') { | ||
element.srcObject = stream; | ||
} else if (typeof element.mozSrcObject !== 'undefined') { | ||
element.mozSrcObject = stream; | ||
} else if (typeof element.src !== 'undefined') { | ||
element.src = URL.createObjectURL(stream); | ||
} else { | ||
return false; | ||
} | ||
return false; | ||
} | ||
return true; | ||
return element; | ||
}; | ||
@@ -26,0 +42,0 @@ |
@@ -1,7 +0,26 @@ | ||
module.exports = function (element, stream, play) { | ||
var autoPlay = (play === false) ? false : true; | ||
module.exports = function (stream, el, options) { | ||
var URL = window.URL; | ||
var opts = { | ||
autoplay: true, | ||
mirror: false, | ||
muted: false | ||
}; | ||
var element = el || document.createElement('video'); | ||
var item; | ||
if (autoPlay) element.autoplay = true; | ||
if (options) { | ||
for (item in options) { | ||
opts[item] = options[item]; | ||
} | ||
} | ||
if (opts.autoplay) element.autoplay = 'autoplay'; | ||
if (opts.muted) element.muted = true; | ||
if (opts.mirror) { | ||
['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) { | ||
var styleName = prefix ? prefix + 'Transform' : 'transform'; | ||
element.style[styleName] = 'scaleX(-1)'; | ||
}); | ||
} | ||
// this first one should work most everywhere now | ||
@@ -8,0 +27,0 @@ // but we have a few fallbacks just in case. |
{ | ||
"name": "attachmediastream", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "cross-browser way to attach a media stream to a video element.", | ||
@@ -14,3 +14,4 @@ "main": "attachmediastream.js", | ||
"browserify", | ||
"WebRTC" | ||
"WebRTC", | ||
"video" | ||
], | ||
@@ -17,0 +18,0 @@ "author": "Henrik Joreteg <henrik@andyet.net>", |
@@ -11,3 +11,2 @@ # attachMediaStream | ||
This module will largely be obsolete once we get `URL.createObjectUrl(stream)` everywhere. | ||
@@ -35,7 +34,29 @@ ## Installing | ||
if (err) { | ||
console.log('failed'); | ||
console.log('failed'); | ||
} else { | ||
console.log('got a stream', stream); | ||
// attaches a stream to an element | ||
attachMediaStream(document.getElementById('myVideo'), stream); | ||
console.log('got a stream', stream); | ||
// attaches a stream to an element (it returns the element) | ||
var videoEl = attachMediaStream(stream, document.getElementById('myVideo')); | ||
// if you don't pass an element it will create a video tag | ||
var generatedVideoEl = attachMediaStream(stream); | ||
// you can also pass options | ||
var videoEl = attachMediaStream(stream, someEl, { | ||
// this will set the autoplay attribute on the video tag | ||
// this is true by default but you can turn it off with this option. | ||
autoplay: true, | ||
// let's you mirror the video. It's false by default, but it's common | ||
// to mirror video when showing a user their own video feed. | ||
// This makes that easy. | ||
mirror: true, | ||
// muted is false, by default | ||
// this will mute the video. Again, this is a good idea when showing | ||
// a user their own video. Or there will be feedback issues. | ||
muted: true | ||
}); | ||
} | ||
@@ -45,10 +66,21 @@ }); | ||
## Why? Browsers do it differently, that's why. | ||
## Why? | ||
This is actually less true than it used to be. It's fairly safe to just use `URL.createObjectUrl(stream)` now. | ||
Browsers used to to this very differently. This is now less true than it used to be. It's fairly safe to just use `URL.createObjectUrl(stream)`. | ||
However, it's nice to know it will work if that's not true and it's also handy to be able to control mirroring, muting, autoplay in one shot with sane defaults. | ||
## Caveats | ||
As of writing this, FireFox doesn't let you show local video feed more than once on a page and trying to do so will result in none of them playing and it appearing broken. | ||
As a result the `test.html` file won't work in FireFox stable unless you do one at a time. | ||
## Other Details | ||
The module's main function returns the element if successful and `false` otherwise. In case that's useful. But if you're able to getUserMedia to begin with, attaching it shouldn't really fail. | ||
The module's main function returns the element if successful and `false` otherwise. But if you're able to getUserMedia to begin with, attaching it shouldn't really fail. | ||
## License | ||
@@ -58,2 +90,3 @@ | ||
## Created By | ||
@@ -60,0 +93,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9336
8
109
1
92
5