FS-8401 refactor the sinkid function into verto lib

This commit is contained in:
Anthony Minessale
2015-11-18 14:43:29 -06:00
parent fb8d4a2b99
commit ae05a19edf
6 changed files with 59 additions and 52 deletions

View File

@@ -2043,6 +2043,53 @@
return false;
}
// Attach audio output device to video element using device/sink ID.
function find_name(id) {
for (var i in $.verto.audioOutDevices) {
var source = $.verto.audioOutDevices[i];
if (source.id === id) {
return(source.label);
}
}
return id;
}
$.verto.dialog.prototype.setAudioPlaybackDevice = function(sinkId, callback, arg) {
var dialog = this;
var element = dialog.audioStream;
if (typeof element.sinkId !== 'undefined') {
var devname = find_name(sinkId);
console.info("Dialog: " + dialog.callID + " Setting speaker:", element, devname);
element.setSinkId(sinkId)
.then(function() {
console.log("Dialog: " + dialog.callID + ' Success, audio output device attached: ' + sinkId);
if (callback) {
callback(true, devname, arg);
}
})
.catch(function(error) {
var errorMessage = error;
if (error.name === 'SecurityError') {
errorMessage = "Dialog: " + dialog.callID + ' You need to use HTTPS for selecting audio output ' +
'device: ' + error;
}
if (callback) {
callback(false, null, arg);
}
console.error(errorMessage);
});
} else {
console.warn("Dialog: " + dialog.callID + ' Browser does not support output device selection.');
if (callback) {
callback(false, null, arg);
}
}
}
$.verto.dialog.prototype.setState = function(state) {
var dialog = this;
@@ -2082,11 +2129,9 @@
console.info("Using Speaker: ", speaker);
if (speaker && speaker !== "any") {
var videoElement = dialog.audioStream;
setTimeout(function() {
console.info("Setting speaker:", videoElement, speaker);
attachSinkId(videoElement, speaker);}, 500);
dialog.setAudioPlaybackDevice(speaker);
}, 500);
}
break;