From ae05a19edfa0c36b820a8285c1b42c2f95849f1e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 18 Nov 2015 14:43:29 -0600 Subject: [PATCH] FS-8401 refactor the sinkid function into verto lib --- html5/verto/js/src/jquery.verto.js | 53 +++++++++++++++++-- .../js/3rd-party/attachSinkId.js | 18 ------- html5/verto/verto_communicator/src/index.html | 1 - .../controllers/MainController.js | 5 +- html5/verto/video_demo/js/verto-min.js | 7 ++- html5/verto/video_demo/verto.js | 27 ---------- 6 files changed, 59 insertions(+), 52 deletions(-) delete mode 100644 html5/verto/verto_communicator/js/3rd-party/attachSinkId.js diff --git a/html5/verto/js/src/jquery.verto.js b/html5/verto/js/src/jquery.verto.js index dba851d3f6..0528652673 100644 --- a/html5/verto/js/src/jquery.verto.js +++ b/html5/verto/js/src/jquery.verto.js @@ -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; diff --git a/html5/verto/verto_communicator/js/3rd-party/attachSinkId.js b/html5/verto/verto_communicator/js/3rd-party/attachSinkId.js deleted file mode 100644 index 9ca286d4a4..0000000000 --- a/html5/verto/verto_communicator/js/3rd-party/attachSinkId.js +++ /dev/null @@ -1,18 +0,0 @@ -function attachSinkId(element, sinkId) { - if (typeof element.sinkId !== 'undefined') { - element.setSinkId(sinkId) - .then(function() { - console.log('Success, audio output device attached:', sinkId); - }) - .catch(function(error) { - var errorMessage = error; - if (error.name === 'SecurityError') { - errorMessage = 'You need to use HTTPS for selecting audio output ' + - 'device: ' + error; - } - console.error(errorMessage); - }); - } else { - console.warn('Browser does not support output device selection.'); - } -} diff --git a/html5/verto/verto_communicator/src/index.html b/html5/verto/verto_communicator/src/index.html index d15c3d9af1..47bdf740cd 100644 --- a/html5/verto/verto_communicator/src/index.html +++ b/html5/verto/verto_communicator/src/index.html @@ -96,7 +96,6 @@ - diff --git a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js index dd4f1cd64f..3c245301a4 100644 --- a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js +++ b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js @@ -36,7 +36,10 @@ }); $rootScope.$on('changedSpeaker', function(event, speakerId) { - attachSinkId(myVideo, speakerId); + // This should provide feedback + //setAudioPlaybackDevice([,[,]]); + // if callback is set it will be called as callback(, , ) + verto.data.call.setAudioPlaybackDevice(speakerId); }); /** diff --git a/html5/verto/video_demo/js/verto-min.js b/html5/verto/video_demo/js/verto-min.js index 51111b5b87..f4e362be1b 100644 --- a/html5/verto/video_demo/js/verto-min.js +++ b/html5/verto/video_demo/js/verto-min.js @@ -257,12 +257,17 @@ if(rtc.type=="offer"){if(dialog.state==$.verto.enum.state.active){dialog.setStat obj.dialogParams[i]=dialog.params[i];} dialog.verto.rpcClient.call(method,obj,function(e){dialog.processReply(method,true,e);},function(e){dialog.processReply(method,false,e);});};function checkStateChange(oldS,newS){if(newS==$.verto.enum.state.purge||$.verto.enum.states[oldS.name][newS.name]){return true;} return false;} +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.setAudioDevice=function(sinkId,callback,arg){var dialog=this;var element=dialog.audioStream;if(typeof element.sinkId!=='undefined'){console.info("Dialog: "+dialog.callID+" Setting speaker:",element,find_name(sinkId));element.setSinkId(sinkId).then(function(){console.log("Dialog: "+dialog.callID+' Success, audio output device attached: '+sinkId);if(callback){callback(true,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,arg);} +console.error(errorMessage);});}else{console.warn("Dialog: "+dialog.callID+' Browser does not support output device selection.');if(callback){callback(false,arg);}}} $.verto.dialog.prototype.setState=function(state){var dialog=this;if(dialog.state==$.verto.enum.state.ringing){dialog.stopRinging();} if(dialog.state==state||!checkStateChange(dialog.state,state)){console.error("Dialog "+dialog.callID+": INVALID state change from "+dialog.state.name+" to "+state.name);dialog.hangup();return false;} console.log("Dialog "+dialog.callID+": state change from "+dialog.state.name+" to "+state.name);dialog.lastState=dialog.state;dialog.state=state;if(!dialog.causeCode){dialog.causeCode=16;} if(!dialog.cause){dialog.cause="NORMAL CLEARING";} if(dialog.callbacks.onDialogState){dialog.callbacks.onDialogState(this);} -switch(dialog.state){case $.verto.enum.state.early:case $.verto.enum.state.active:var speaker=dialog.useSpeak;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);} +switch(dialog.state){case $.verto.enum.state.early:case $.verto.enum.state.active:var speaker=dialog.useSpeak;console.info("Using Speaker: ",speaker);if(speaker&&speaker!=="any"){setTimeout(function(){dialog.setAudioDevice(speaker);},500);} break;case $.verto.enum.state.trying:setTimeout(function(){if(dialog.state==$.verto.enum.state.trying){dialog.setState($.verto.enum.state.hangup);}},30000);break;case $.verto.enum.state.purge:dialog.setState($.verto.enum.state.destroy);break;case $.verto.enum.state.hangup:if(dialog.lastState.val>$.verto.enum.state.requesting.val&&dialog.lastState.val<$.verto.enum.state.hangup.val){dialog.sendMethod("verto.bye",{});} dialog.setState($.verto.enum.state.destroy);break;case $.verto.enum.state.destroy:delete dialog.verto.dialogs[dialog.callID];if(dialog.params.screenShare){dialog.rtc.stopPeer();}else{dialog.rtc.stop();} break;} diff --git a/html5/verto/video_demo/verto.js b/html5/verto/video_demo/verto.js index 31bb147da3..a4c71c36b3 100644 --- a/html5/verto/video_demo/verto.js +++ b/html5/verto/video_demo/verto.js @@ -234,33 +234,6 @@ function do_speed_test(fn) }); } - -// Attach audio output device to video element using device/sink ID. - -function attachSinkId(element, sinkId) { - if (typeof element.sinkId !== 'undefined') { - element.setSinkId(sinkId) - .then(function() { - console.log('Success, audio output device attached: ' + sinkId); - }) - .catch(function(error) { - var errorMessage = error; - if (error.name === 'SecurityError') { - errorMessage = 'You need to use HTTPS for selecting audio output ' + - 'device: ' + error; - } - console.error(errorMessage); - // Jump back to first output device in the list as it's the default. - //audioOutputSelect.selectedIndex = 0; - }); - } else { - console.warn('Browser does not support output device selection.'); - } -} - - - - function messageTextToJQ(body) { // Builds a jQuery collection from body text, linkifies http/https links, imageifies http/https links to images, and doesn't allow script injection