-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattachstream.js
49 lines (39 loc) · 1.07 KB
/
attachstream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var canUseURL = typeof window.URL != 'undefined';
module.exports = function(stream, el, opts, callback) {
if (typeof opts == 'function') {
callback = opts;
opts = {};
}
function ready() {
var autoplay = (opts || {}).autoplay;
el.removeEventListener('canplay', ready);
el.removeEventListener('loadedmetadata', ready);
if (typeof autoplay == 'undefined' || autoplay) {
el.play();
}
callback();
}
// check for srcObject
if (typeof el.srcObject != 'undefined') {
video.srcObject = stream;
}
// check for mozSrcObject
else if (typeof el.mozSrcObject != 'undefined') {
el.mozSrcObject = stream;
}
else {
el.src = canUseURL ? URL.createObjectURL(stream) : stream;
}
// if no callback has been provided, return without monitoring the readiness
if (! callback) {
return;
}
// if the video is ready now, then capture the frame
if (el.readyState >= 3) {
return callback();
}
else {
el.addEventListener('canplay', ready, false);
el.addEventListener('loadedmetadata', ready, false);
}
};