forked from jitsi/react-native-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRTCUtil.js
25 lines (24 loc) · 919 Bytes
/
RTCUtil.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
'use strict';
/**
* Merge custom constraints with the default one. The custom one take precedence.
*
* @param {Object} custom - custom webrtc constraints
* @param {Object} def - default webrtc constraints
* @return {Object} constraints - merged webrtc constraints
*/
export function mergeMediaConstraints(custom, def) {
const constraints = (def ? Object.assign({}, def) : {});
if (custom) {
if (custom.mandatory) {
constraints.mandatory = {...constraints.mandatory, ...custom.mandatory};
}
if (custom.optional && Array.isArray(custom.optional)) {
// `optional` is an array, webrtc only finds first and ignore the rest if duplicate.
constraints.optional = custom.optional.concat(constraints.optional);
}
if (custom.facingMode) {
constraints.facingMode = custom.facingMode.toString(); // string, 'user' or the default 'environment'
}
}
return constraints;
}