2017-12-07 11 views
1

우리는 사용자가 다른 사용자와 화상 채팅을 할 수있는 웹 응용 프로그램을 만들고 있습니다. PC의 내장 마이크와 다른 입력 장치 사이의 오디오 입력을 전환 할 수있는 옵션을 제공하고자합니다. 나는 인터넷에서 동일한 것에 대해 검색하려했지만 어떤 단서도 찾지 못했습니다.MVC를 사용하는 웹 응용 프로그램에서 한 장치에서 다른 장치로 오디오 입력을 변경하려면 어떻게합니까?

답변

1

(opentok 태그를 사용했기 때문에) opentok을 사용한다고 가정합니다.

OT.getDevices API를 사용하여 사용 가능한 오디오 입력 장치를 나열 할 수 있습니다. 그런 다음 게시 할 때 장치를 전달할 수 있습니다. 뭔가 같은 :

let publisher; 
function publish(audioDeviceId) { 
    if (publisher) { 
    publisher.destroy(); 
    } 
    publisher = OT.initPublisher(null, { 
    audioSource: audioDeviceId 
    }); 
} 

publish(); 

OT.getDevices((err, devices) => { 
    if (!err) { 
    let select = document.querySelector('select'); 
    devices.filter(device => device.kind === 'audioInput').forEach(device => { 
     let option = document.createElement('option'); 
     option.value = device.deviceId; 
     option.innerHTML = device.label; 
     select.appendChild(option); 
    }); 
    select.addEventListener('change',() => { 
     publish(event.target.value); 
    }); 
    } 
}); 

당신은 https://jsbin.com/qibaba

에서 작동하는 데모를 볼 수 있습니다