mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 09:36:46 +00:00
FS-8401 refactor the sinkid function into verto lib
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user