Call Us Today! 877.742.2583




Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

About

Example of calling a dtmf callback function while playing a file.

 

 Click here to expand Table of Contents

Example JS Code

 

DTMF callback example
/* example of calling a dtmf callback function while playing a file. */
function onPlayFile(s, type, obj, arg)
{
   try {
      if (type == "dtmf") {
         console_log("info", "DTMF digit: " + s.name + " [" + obj.digit + "] len [" + obj.duration + "]\n\n");

         // below are some controls available to javascript input callback
         // not all are 100% tested in this example, please check mod_spidermonkey if they do not work for you
         // if you do not require playback control, the entire following block can be removed
         if (obj.digit == "3") {
            return "seek:+5000"; // seek forwards (testing needed)
         }
         else if (obj.digit == "1") {
            return "seek:-5000"; // seek backwards (testing needed)
         }
         else if (obj.digit == "2") {
            return "volume:+1"; // volume up (testing needed)
         }
         else if (obj.digit == "3") {
            return "volume:-1"; // volume down (testing needed)
         }
         else if (obj.digit == "5") {
            return "pause"; // pauses and unpauses
         }
         else if (obj.digit == "6") {
            return "restart"; // seek to the beginning of the file
         }
         else if (obj.digit == "7") {
            return "speed:+1"; // increase playback speed (testing needed)
         }
         else if (obj.digit == "8") {
            return "speed:-1"; // decrease playback speed (testing needed)
         }
         else if (obj.digit == "9") {
            return true; // return without interrupting playback of streamFile
         }
         else if (obj.digit == "*") {
            return false; // stop playback and break from streamFile
         }

      }
   }  catch (e) {
      console_log("err", e + "\n");
   }
   return true;
}

session.answer();

while(session.ready()) {
   session.streamFile(argv[0], onPlayFile);
}
  • No labels