2017-10-26 04:50:22 +00:00
|
|
|
define(["helper/Basic", "Tone/source/UserMedia", "Test", "Tone/source/Source"],
|
2017-02-20 21:45:32 +00:00
|
|
|
function (BasicTests, UserMedia, Test, Source) {
|
2016-12-17 21:26:27 +00:00
|
|
|
|
|
|
|
describe("UserMedia", function(){
|
|
|
|
|
|
|
|
//run the common tests
|
|
|
|
BasicTests(UserMedia);
|
|
|
|
|
|
|
|
context("Source Tests", function(){
|
|
|
|
|
|
|
|
it ("can connect the output", function(){
|
|
|
|
var extIn = new UserMedia();
|
|
|
|
extIn.connect(Test);
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("can be constructed with the input number", function(){
|
|
|
|
var extIn = new UserMedia();
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("can be constructed with an options object", function(){
|
|
|
|
var extIn = new UserMedia({
|
2017-04-30 18:25:44 +00:00
|
|
|
"volume" : -10,
|
|
|
|
"mute" : false
|
2016-12-17 21:26:27 +00:00
|
|
|
});
|
|
|
|
expect(extIn.volume.value).to.be.closeTo(-10, 0.1);
|
2017-04-30 18:25:44 +00:00
|
|
|
expect(extIn.mute).to.be.false;
|
2016-12-17 21:26:27 +00:00
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("indicates if the browser has UserMedia support", function(){
|
|
|
|
expect(UserMedia.supported).to.be.a.boolean;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//if it is a manual test (i.e. there is a person to 'allow' the microphone)
|
2017-04-30 17:49:04 +00:00
|
|
|
if (UserMedia.supported){
|
2016-12-17 21:26:27 +00:00
|
|
|
|
|
|
|
context("Opening and closing", function(){
|
|
|
|
|
|
|
|
//long timeout to give testers time to allow the microphone
|
|
|
|
this.timeout(100000);
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("open returns a promise", function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
var extIn = new UserMedia();
|
|
|
|
var promise = extIn.open();
|
|
|
|
expect(promise).to.be.instanceOf(Promise);
|
2017-05-03 00:58:44 +00:00
|
|
|
return promise.then(function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
extIn.dispose();
|
2017-04-30 17:49:04 +00:00
|
|
|
});
|
2016-12-17 21:26:27 +00:00
|
|
|
});
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("can open an input", function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
var extIn = new UserMedia();
|
2017-05-03 00:58:44 +00:00
|
|
|
return extIn.open().then(function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("can open an input by name", function(){
|
|
|
|
var extIn = new UserMedia();
|
2017-10-26 04:50:22 +00:00
|
|
|
var name = null
|
|
|
|
return UserMedia.enumerateDevices().then(function(devices){
|
|
|
|
name = devices[0].deviceId
|
|
|
|
return extIn.open(name)
|
|
|
|
}).then(function(){
|
|
|
|
expect(extIn.deviceId).to.equal(name);
|
2017-05-03 00:58:44 +00:00
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("can open an input by index", function(){
|
|
|
|
var extIn = new UserMedia();
|
|
|
|
return extIn.open(0).then(function(){
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("throws an error if it cant find the device name", function(){
|
|
|
|
var extIn = new UserMedia();
|
|
|
|
return extIn.open("doesn't exist").catch(function(){
|
|
|
|
extIn.dispose();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("is 'started' after media is open and 'stopped' otherwise", function(){
|
2017-04-30 18:25:44 +00:00
|
|
|
var extIn = new UserMedia();
|
|
|
|
expect(extIn.state).to.equal("stopped");
|
2017-05-03 00:58:44 +00:00
|
|
|
return extIn.open().then(function(){
|
2017-04-30 18:25:44 +00:00
|
|
|
expect(extIn.state).to.equal("started");
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("has a label, group and device id when open", function(){
|
2017-04-30 18:25:44 +00:00
|
|
|
var extIn = new UserMedia();
|
2017-05-03 00:58:44 +00:00
|
|
|
return extIn.open().then(function(){
|
2017-04-30 18:25:44 +00:00
|
|
|
expect(extIn.deviceId).to.be.a("string");
|
|
|
|
expect(extIn.groupId).to.be.a("string");
|
|
|
|
expect(extIn.label).to.be.a("string");
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("can close an input", function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
var extIn = new UserMedia();
|
2017-05-03 00:58:44 +00:00
|
|
|
return extIn.open().then(function(){
|
2016-12-17 21:26:27 +00:00
|
|
|
extIn.close();
|
|
|
|
extIn.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-03 00:58:44 +00:00
|
|
|
it ("can enumerate devices", function(){
|
|
|
|
return UserMedia.enumerateDevices().then(function(devices){
|
2016-12-17 21:26:27 +00:00
|
|
|
expect(devices).to.be.instanceOf(Array);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2017-10-26 04:50:22 +00:00
|
|
|
});
|