Skip to content

Commit a4f5764

Browse files
committed
Added simple attachstream implementation
1 parent 28eacd5 commit a4f5764

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

attachstream.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var canUseURL = typeof window.URL != 'undefined';
2+
3+
module.exports = function(el, stream, callback) {
4+
5+
function ready() {
6+
el.removeEventListener('canplay', ready);
7+
el.removeEventListener('loadedmetadata', ready);
8+
}
9+
10+
// check for srcObject
11+
if (typeof el.srcObject != 'undefined') {
12+
video.srcObject = stream;
13+
}
14+
// check for mozSrcObject
15+
else if (typeof el.mozSrcObject != 'undefined') {
16+
el.mozSrcObject = stream;
17+
}
18+
else {
19+
el.src = canUseURL ? URL.createObjectURL(stream) : stream;
20+
}
21+
22+
// if no callback has been provided, return without monitoring the readiness
23+
if (! callback) {
24+
return;
25+
}
26+
27+
// if the video is ready now, then capture the frame
28+
if (el.readyState >= 3) {
29+
return callback();
30+
}
31+
else {
32+
el.addEventListener('canplay', ready, false);
33+
el.addEventListener('loadedmetadata', ready, false);
34+
}
35+
36+
};

0 commit comments

Comments
 (0)