mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
throwing error when passed in device is not found
This commit is contained in:
parent
b0a0ff2a38
commit
cb1937062c
1 changed files with 6 additions and 9 deletions
|
@ -91,7 +91,7 @@ define(["Tone/core/Tone", "Tone/component/Volume"], function(Tone){
|
|||
*/
|
||||
Tone.UserMedia.prototype.open = function(labelOrId){
|
||||
labelOrId = Tone.defaultArg(labelOrId, "default");
|
||||
return this.enumerateDevices().then(function(devices){
|
||||
return Tone.UserMedia.enumerateDevices().then(function(devices){
|
||||
var device;
|
||||
if (Tone.isNumber(labelOrId)){
|
||||
device = devices[labelOrId];
|
||||
|
@ -99,15 +99,11 @@ define(["Tone/core/Tone", "Tone/component/Volume"], function(Tone){
|
|||
device = devices.find(function(device){
|
||||
return device.label === labelOrId || device.deviceId === labelOrId;
|
||||
});
|
||||
//didn't find a matching device
|
||||
if (!device){
|
||||
//otherwise just take the first one
|
||||
device = devices[0];
|
||||
throw new Error("Tone.UserMedia: no matching device: "+labelOrId);
|
||||
}
|
||||
}
|
||||
//didn't find a matching device
|
||||
if (!device){
|
||||
throw new Error("Tone.UserMedia: no matching audio inputs.");
|
||||
}
|
||||
this._device = device;
|
||||
//do getUserMedia
|
||||
var constraints = {
|
||||
|
@ -152,12 +148,13 @@ define(["Tone/core/Tone", "Tone/component/Volume"], function(Tone){
|
|||
/**
|
||||
* Returns a promise which resolves with the list of audio input devices available.
|
||||
* @return {Promise} The promise that is resolved with the devices
|
||||
* @static
|
||||
* @example
|
||||
* extInput.enumerateDevices().then(function(devices){
|
||||
* Tone.UserMedia.enumerateDevices().then(function(devices){
|
||||
* console.log(devices)
|
||||
* })
|
||||
*/
|
||||
Tone.UserMedia.prototype.enumerateDevices = function(){
|
||||
Tone.UserMedia.enumerateDevices = function(){
|
||||
return navigator.mediaDevices.enumerateDevices().then(function(devices){
|
||||
return devices.filter(function(device){
|
||||
return device.kind === "audioinput";
|
||||
|
|
Loading…
Reference in a new issue