forked from otalk/attachMediaStream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattachmediastream.js
More file actions
47 lines (40 loc) · 1.2 KB
/
attachmediastream.js
File metadata and controls
47 lines (40 loc) · 1.2 KB
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
var adapter = require('webrtc-adapter');
module.exports = function (stream, el, options) {
var item;
var element = el;
var opts = {
autoplay: true,
mirror: false,
muted: false,
audio: false,
disableContextMenu: false
};
if (options) {
for (item in options) {
opts[item] = options[item];
}
}
if (!element) {
element = document.createElement(opts.audio ? 'audio' : 'video');
} else if (element.tagName.toLowerCase() === 'audio') {
opts.audio = true;
}
if (opts.disableContextMenu) {
element.oncontextmenu = function (e) {
e.preventDefault();
};
}
if (opts.autoplay) element.autoplay = 'autoplay';
element.muted = !!opts.muted;
if (!opts.audio) {
['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) {
var styleName = prefix ? prefix + 'Transform' : 'transform';
element.style[styleName] = opts.mirror ? 'scaleX(-1)' : 'scaleX(1)';
});
}
if (adapter.browserDetails.browser === 'safari') {
element.setAttribute('playsinline', true);
}
element.srcObject = stream;
return element;
};