wrtc.onSources() is called when list of available local audio and video sources has been populated.
wrtc.onSources() occur only in Chrome and Safari browsers. If other browser is used wrtc.onSources() never occur.
You can use this event function to call wrtc.get("audioSources") and wrtc.get("videoSources") and allow user select which camera and microphone to use.
List of audio and video sources has been populated.
As the Chrome browser takes a while to populate the sources lists they cannot be accessed right away after page has been loaded. Do not attempt to wrtc.get() the lists in wrtc.init(). Once Chrome has finished preparing the lists wrtc.onSources() will occur indicating you are welcome to access the lists using wrtc.get()
wrtc.onSources()
Fill <select> dropdown asource with entries from audio_sources:
wrtc.onSources() {
var audio_sources = wrtc.get("audioSources");
for (var i = 0; i < audio_sources.length; i++) {
var option = document.createElement("option");
option.text = audio_sources[i].label || 'microphone ' + (i + 1);
option.value = audio_sources[i].id;
document.getElementById('asource').add(option);
}
-- same for video --
}
...
<select id="asource">
<option value=0 selected>default</option>
</select>
User can later select microphone from list of available ones in dropdown asource, set wrtc.audioSource to selected dropdown value and call wrtc.changeMedia(). And the same for video.