Commit a2f18bba by Иван Кубота

get devices

parent de54ce47
......@@ -2,3 +2,4 @@ build/apps
build/awrtc
build/bundle
node_modules
.idea
\ No newline at end of file
......@@ -178,6 +178,66 @@
)
)
);
function gotDevices(deviceInfos) {
// Handles being called several times to update labels. Preserve values.
var devices = {audioinput: [], audiooutput: [], videoinput: []};
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
const option = {value: deviceInfo.deviceId};
if(!(deviceInfo.kind in devices)){
devices[ deviceInfo.kind ] = [];
}
devices[deviceInfo.kind].push(option);
var count = devices[deviceInfo.kind].length;
if (deviceInfo.kind === 'audioinput') {
option.text = deviceInfo.label || `microphone ${count}`;
} else if (deviceInfo.kind === 'audiooutput') {
option.text = deviceInfo.label || `speaker ${count}`;
} else if (deviceInfo.kind === 'videoinput') {
option.text = deviceInfo.label || `camera ${count}`;
} else {
console.log('Some other kind of source/device: ', deviceInfo);
}
}
console.log(devices);
/*const values = selectors.map(select => select.value);
selectors.forEach(select => {
while (select.firstChild) {
select.removeChild(select.firstChild);
}
});
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
const option = document.createElement('option');
option.value = deviceInfo.deviceId;
if (deviceInfo.kind === 'audioinput') {
option.text = deviceInfo.label || `microphone ${audioInputSelect.length + 1}`;
audioInputSelect.appendChild(option);
} else if (deviceInfo.kind === 'audiooutput') {
option.text = deviceInfo.label || `speaker ${audioOutputSelect.length + 1}`;
audioOutputSelect.appendChild(option);
} else if (deviceInfo.kind === 'videoinput') {
option.text = deviceInfo.label || `camera ${videoSelect.length + 1}`;
videoSelect.appendChild(option);
} else {
console.log('Some other kind of source/device: ', deviceInfo);
continue;
}
}
selectors.forEach((select, selectorIndex) => {
if (Array.prototype.slice.call(select.childNodes).some(n => n.value === values[selectorIndex])) {
select.value = values[selectorIndex];
}
});*/
}
var handleError = function(e) {
console.log('Error', e)
}
navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError);
const videoElement = document.getElementsByClassName('input_video')[0];
const canvasElement = window.canvasElement =document.getElementsByClassName('output_canvas')[0];
const segmentations = [false,false,false,false];
......@@ -251,15 +311,19 @@
let instance =new apps.videoinputapp(document.querySelector("#videoinputapp1"), canvas);
instance.mUiRemoteVideoParent = remoteVideoEl;
const selfieSegmentation = new SelfieSegmentation({locateFile: (file) => {
var doSegmentation = false;
if(doSegmentation){
const selfieSegmentation = new SelfieSegmentation( {
locateFile: ( file ) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation/${file}`;
}});
selfieSegmentation.setOptions({
}
} );
selfieSegmentation.setOptions( {
modelSelection: 1,
});
selfieSegmentation.onResults(function() {
window.onResults.apply(this, arguments)
});
} );
selfieSegmentation.onResults( function(){
window.onResults.apply( this, arguments )
} );
const camera = new Camera(videoElement, {
onFrame: async () => {
......@@ -269,6 +333,7 @@
height: h//,720
});
camera.start();
}
D.ext(D('.callapp_button')[0], {onclick: function() {
}});
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment