]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8401 refactor the sinkid function into verto lib
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 18 Nov 2015 20:43:29 +0000 (14:43 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 18 Nov 2015 20:43:29 +0000 (14:43 -0600)
html5/verto/js/src/jquery.verto.js
html5/verto/verto_communicator/js/3rd-party/attachSinkId.js [deleted file]
html5/verto/verto_communicator/src/index.html
html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js
html5/verto/video_demo/js/verto-min.js
html5/verto/video_demo/verto.js

index dba851d3f638e31ddf092547228cb7068186b67f..0528652673b52518f2347e006555db723dbe535a 100644 (file)
         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;
 
            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 (file)
index 9ca286d..0000000
+++ /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.');
-  }
-}
index d15c3d9af1281364880b14d908e67efb1ff88bb4..47bdf740cdd334c0700155110df13bbdefda809b 100644 (file)
@@ -96,7 +96,6 @@
     <script type="text/javascript" src="js/3rd-party/getScreenId.js"></script>
     <script type="text/javascript" src="js/3rd-party/md5.min.js"></script>
     <script type="text/javascript" src="js/3rd-party/volume-meter.js"></script>
-    <script type="text/javascript" src="js/3rd-party/attachSinkId.js"></script>
 
     <script type="text/javascript" src="src/vertoApp/vertoApp.module.js"></script>
 
index dd4f1cd64f7c8faa727bf6dac35c923c741061c4..3c245301a4a5b2aaed3817bc849f7c78ccb232fd 100644 (file)
       });
 
       $rootScope.$on('changedSpeaker', function(event, speakerId) {
-        attachSinkId(myVideo, speakerId);
+        // This should provide feedback
+       //setAudioPlaybackDevice(<id>[,<callback>[,<callback arg>]]);
+       // if callback is set it will be called as callback(<bool success/fail>, <device name>, <arg if you supplied it>)
+        verto.data.call.setAudioPlaybackDevice(speakerId);
       });
 
       /**
index 51111b5b87ccdcfbfaa11d95a90304688057be76..f4e362be1bfe77b3eaae0136b0ddc515c090bcc5 100644 (file)
@@ -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;}
index 31bb147da3dca66cb97ff432c63250816fbaeadc..a4c71c36b3d25f1a1d4ea0ac371ab9c1d2bd33c6 100644 (file)
@@ -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