<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Michael.<br>
    <br>
    Yes, you are right, maybe the better is to use ESL. <br>
    My script is basically an IVR. When all the audio files are played,
    then wait until the user press a dtmf key or timeout occur. Because
    there are a lot of files to play based on caller ID, I wait for the
    user input at the end of the script, but prior to finish the script,
    because hangsup.<br>
    <br>
    I workaround this with:<br>
    <br>
    session.collectInput(onPlay, services, afterMenuTimeOut,
    totalTimeOut);<br>
    playTimeout(despedida)<br>
    <br>
    and return always "true" from "onPlay" callback.<br>
    <br>
    Respond to your question, this is the function I want to run in
    setTimeout:<br>
    <br>
    function playTimeout(despedida){<br>
        if (session.ready()) {<br>
            logger("TIMEOUT");<br>
            session.execute("sleep","400");<br>
            session.execute("playback", sonidos + "/TIMEOUT.wav");<br>
            session.execute("sleep","400");<br>
            logger(despedida);<br>
            session.execute("playback", sonidos + "/" + despedida +
    ".wav");<br>
            session.hangup();<br>
        }<br>
        exit("TIMEOUT");<br>
    }<br>
    <br>
    Thanks<br>
    Normando<br>
    <br>
    <div class="moz-cite-prefix">El 25/01/2016 a las 05:20 p.m., Michael
      Jerris escribió:<br>
    </div>
    <blockquote
cite="mid:CAEwTsAjhdo8qZcixOuEOt3JFr8cPYWBLwTSKOamQBNGRmTWwJQ@mail.gmail.com"
      type="cite">What exactly is the javascript doing when you want to
      call that callback?  this is probably not possible due to how the
      JavaScript is blocked by native functions when doing actions such
      as handling audio due to the threading model of the embedded
      languages.  They run in the session thread so they are not as
      async as people tend to be used to with js.   This sort of
      approach might be more appropriate when using js in a remote
      control type structure such as when controlling a session over
      esl, but not in the embedded mod_v8.  we have discussed doing a
      truly async type control for embedded languages but have never
      implemented it.<span></span>
      <div><br>
        On Monday, January 25, 2016, Normando Hall &lt;<a
          moz-do-not-send="true" href="mailto:nhall@unixlan.com.ar"><a class="moz-txt-link-abbreviated" href="mailto:nhall@unixlan.com.ar">nhall@unixlan.com.ar</a></a>&gt;
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor="#FFFFFF" text="#000000"> Thanks Matt, I can play
            a file, but still can't run the function. Are there any
            application can run a function instead a file?<br>
            <br>
            Thanks!<br>
            Normando<br>
            <br>
            <br>
            <div>El 25/01/2016 a las 05:59 a.m., Matt Broad escribió:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">try using the 1 liner sched_broadcast <a
                  moz-do-not-send="true"
href="https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast"
                  target="_blank"><a class="moz-txt-link-freetext" href="https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast">https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast</a></a>
                <div><br>
                </div>
                <div>The below will schedule a broadcast to play
                  /tmp/hangupfile.mp3 to both legs after 60 seconds. </div>
                <div><br>
                </div>
                <div><i>maxTimeTaskID = </i><i>session.execute("sched_broadcast",

                    "+60 playback!normal_clearing::/tmp/hangupfile.mp3
                    both")</i>;<br>
                </div>
                <div><br>
                </div>
                <div>If you find you need to cancel the broadcast use:</div>
                <div><br>
                </div>
                <div><i>session.execute("sched_cancel",maxTimeTaskID);</i><br>
                </div>
                <div><br>
                </div>
                <div>hope this helps.</div>
                <div><br>
                </div>
                <div>thanks</div>
                <div>Matt</div>
              </div>
              <div class="gmail_extra"><br>
                <div class="gmail_quote">On 25 January 2016 at 06:58, <span
                    dir="ltr">&lt;<a moz-do-not-send="true"
                      href="javascript:_e(%7B%7D,'cvml','royj@yandex.ru');"
                      target="_blank">royj@yandex.ru</a>&gt;</span>
                  wrote:<br>
                  <blockquote class="gmail_quote" style="margin:0 0 0
                    .8ex;border-left:1px #ccc solid;padding-left:1ex">have
                    no relationship to the resource, but first link to
                    request 'asynchronous code javascript'<br>
                    <br>
                    <a moz-do-not-send="true"
href="http://www.hiddenwebgenius.com/blog/guides/understanding-javascripts-asynchronous-code/"
                      rel="noreferrer" target="_blank">http://www.hiddenwebgenius.com/blog/guides/understanding-javascripts-asynchronous-code/</a><br>
                    <br>
                    25.01.2016, 09:16, "Normando Hall" &lt;<a
                      moz-do-not-send="true"
                      href="javascript:_e(%7B%7D,'cvml','nhall@unixlan.com.ar');"
                      target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:nhall@unixlan.com.ar">nhall@unixlan.com.ar</a></a>&gt;:<br>
                    <div>
                      <div>&gt; Sorry, I missed to say it is Freeswitch
                        1.4<br>
                        &gt;<br>
                        &gt; El 25/01/2016 a las 02:53 a.m., Normando
                        Hall escribió:<br>
                        &gt;&gt;  Hello everybody.<br>
                        &gt;&gt;<br>
                        &gt;&gt;  I am coding a js script to do
                        somethings, and I want to add a global<br>
                        &gt;&gt;  timeout, to call a function to play a
                        file and hangup. But the function<br>
                        &gt;&gt;  called inmediatelly.<br>
                        &gt;&gt;  Also tested with setInterval, the same
                        behaviour.<br>
                        &gt;&gt;<br>
                        &gt;&gt;  function playTimeout(despedida){<br>
                        &gt;&gt;      if (session.ready()) {<br>
                        &gt;&gt;          logger("TIMEOUT");<br>
                        &gt;&gt;          session.execute("playback",
                        sonidos + "/TIMEOUT.wav");<br>
                        &gt;&gt;
                                 session.execute("sleep","500");<br>
                        &gt;&gt;          logger(despedida);<br>
                        &gt;&gt;          session.execute("playback",
                        sonidos + "/" + despedida + ".wav");<br>
                        &gt;&gt;          session.hangup();<br>
                        &gt;&gt;      }<br>
                        &gt;&gt;      exit("TIMEOUT");<br>
                        &gt;&gt;  }<br>
                        &gt;&gt;<br>
                        &gt;&gt;
                         setTimeout(playTimeout(despedida),120000);<br>
                        &gt;&gt;  .<br>
                        &gt;&gt;  .<br>
                        &gt;&gt;  .<br>
                        &gt;&gt;  my script continue<br>
                        &gt;&gt;<br>
                        &gt;&gt;  Any help is welcome!<br>
                        &gt;&gt;<br>
                        &gt;&gt;  Thank you<br>
                        &gt;&gt;  Normando<br>
                        &gt;&gt;<br>
                        &gt;&gt;
 _________________________________________________________________________<br>
                        &gt;&gt;  Professional FreeSWITCH Consulting
                        Services:<br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="javascript:_e(%7B%7D,'cvml','consulting@freeswitch.org');"
                          target="_blank">consulting@freeswitch.org</a><br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://www.freeswitchsolutions.com"
                          rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
                        &gt;&gt;<br>
                        &gt;&gt;  Official FreeSWITCH Sites<br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://confluence.freeswitch.org"
                          rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://www.cluecon.com" rel="noreferrer"
                          target="_blank">http://www.cluecon.com</a><br>
                        &gt;&gt;<br>
                        &gt;&gt;  FreeSWITCH-users mailing list<br>
                        &gt;&gt;  <a moz-do-not-send="true"
href="javascript:_e(%7B%7D,'cvml','FreeSWITCH-users@lists.freeswitch.org');"
                          target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
                        &gt;&gt;  UNSUBSCRIBE:<a moz-do-not-send="true"
href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
                        &gt;&gt;  <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
                        &gt;<br>
                        &gt;
_________________________________________________________________________<br>
                        &gt; Professional FreeSWITCH Consulting
                        Services:<br>
                        &gt; <a moz-do-not-send="true"
                          href="javascript:_e(%7B%7D,'cvml','consulting@freeswitch.org');"
                          target="_blank">consulting@freeswitch.org</a><br>
                        &gt; <a moz-do-not-send="true"
                          href="http://www.freeswitchsolutions.com"
                          rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
                        &gt;<br>
                        &gt; Official FreeSWITCH Sites<br>
                        &gt; <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
                        &gt; <a moz-do-not-send="true"
                          href="http://confluence.freeswitch.org"
                          rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
                        &gt; <a moz-do-not-send="true"
                          href="http://www.cluecon.com" rel="noreferrer"
                          target="_blank">http://www.cluecon.com</a><br>
                        &gt;<br>
                        &gt; FreeSWITCH-users mailing list<br>
                        &gt; <a moz-do-not-send="true"
href="javascript:_e(%7B%7D,'cvml','FreeSWITCH-users@lists.freeswitch.org');"
                          target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
                        &gt; <a moz-do-not-send="true"
                          href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
                        &gt; UNSUBSCRIBE:<a moz-do-not-send="true"
                          href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
                        &gt; <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
                        <br>
_________________________________________________________________________<br>
                        Professional FreeSWITCH Consulting Services:<br>
                        <a moz-do-not-send="true"
                          href="javascript:_e(%7B%7D,'cvml','consulting@freeswitch.org');"
                          target="_blank">consulting@freeswitch.org</a><br>
                        <a moz-do-not-send="true"
                          href="http://www.freeswitchsolutions.com"
                          rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
                        <br>
                        Official FreeSWITCH Sites<br>
                        <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
                        <a moz-do-not-send="true"
                          href="http://confluence.freeswitch.org"
                          rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
                        <a moz-do-not-send="true"
                          href="http://www.cluecon.com" rel="noreferrer"
                          target="_blank">http://www.cluecon.com</a><br>
                        <br>
                        FreeSWITCH-users mailing list<br>
                        <a moz-do-not-send="true"
href="javascript:_e(%7B%7D,'cvml','FreeSWITCH-users@lists.freeswitch.org');"
                          target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
                        <a moz-do-not-send="true"
                          href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
                        UNSUBSCRIBE:<a moz-do-not-send="true"
                          href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
                          rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
                        <a moz-do-not-send="true"
                          href="http://www.freeswitch.org"
                          rel="noreferrer" target="_blank">http://www.freeswitch.org</a></div>
                    </div>
                  </blockquote>
                </div>
                <br>
              </div>
              <br>
              <fieldset></fieldset>
              <br>
              <pre>_________________________________________________________________________
Professional FreeSWITCH Consulting Services: 
<a moz-do-not-send="true" href="javascript:_e(%7B%7D,'cvml','consulting@freeswitch.org');" target="_blank">consulting@freeswitch.org</a>
<a moz-do-not-send="true" href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a>

Official FreeSWITCH Sites
<a moz-do-not-send="true" href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a>
<a moz-do-not-send="true" href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a>
<a moz-do-not-send="true" href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a>

FreeSWITCH-users mailing list
<a moz-do-not-send="true" href="javascript:_e(%7B%7D,'cvml','FreeSWITCH-users@lists.freeswitch.org');" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a>
<a moz-do-not-send="true" href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a moz-do-not-send="true" href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a moz-do-not-send="true" href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></pre>
            </blockquote>
            <br>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_________________________________________________________________________
Professional FreeSWITCH Consulting Services: 
<a class="moz-txt-link-abbreviated" href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a>

Official FreeSWITCH Sites
<a class="moz-txt-link-freetext" href="http://www.freeswitch.org">http://www.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://confluence.freeswitch.org">http://confluence.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://www.cluecon.com">http://www.cluecon.com</a>

FreeSWITCH-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a class="moz-txt-link-freetext" href="http://www.freeswitch.org">http://www.freeswitch.org</a></pre>
    </blockquote>
    <br>
  </body>
</html>