<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">&nbsp;If you are trying to trigger that code to run at a specific time, regardless of what else it is doing, that will be very difficult to do with embedded js, and running with something async is probably required. &nbsp;A note, you might want to look at phrase macros as they will greatly simplify some of that code as well.\<div class="">Mike</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 25, 2016, at 4:24 PM, Normando Hall &lt;<a href="mailto:nhall@unixlan.com.ar" class="">nhall@unixlan.com.ar</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">
  
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type" class="">
  
  <div bgcolor="#FFFFFF" text="#000000" class="">
    Hi Michael.<br class="">
    <br class="">
    Yes, you are right, maybe the better is to use ESL. <br class="">
    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 class="">
    <br class="">
    I workaround this with:<br class="">
    <br class="">
    session.collectInput(onPlay, services, afterMenuTimeOut,
    totalTimeOut);<br class="">
    playTimeout(despedida)<br class="">
    <br class="">
    and return always "true" from "onPlay" callback.<br class="">
    <br class="">
    Respond to your question, this is the function I want to run in
    setTimeout:<br class="">
    <br class="">
    function playTimeout(despedida){<br class="">
    &nbsp;&nbsp;&nbsp; if (session.ready()) {<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; logger("TIMEOUT");<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; session.execute("sleep","400");<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; session.execute("playback", sonidos + "/TIMEOUT.wav");<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; session.execute("sleep","400");<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; logger(despedida);<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; session.execute("playback", sonidos + "/" + despedida +
    ".wav");<br class="">
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; session.hangup();<br class="">
    &nbsp;&nbsp;&nbsp; }<br class="">
    &nbsp;&nbsp;&nbsp; exit("TIMEOUT");<br class="">
    }<br class="">
    <br class="">
    Thanks<br class="">
    Normando<br class="">
    <br class="">
    <div class="moz-cite-prefix">El 25/01/2016 a las 05:20 p.m., Michael
      Jerris escribió:<br class="">
    </div>
    <blockquote cite="mid:CAEwTsAjhdo8qZcixOuEOt3JFr8cPYWBLwTSKOamQBNGRmTWwJQ@mail.gmail.com" type="cite" class="">What exactly is the javascript doing when you want to
      call that callback? &nbsp;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.&nbsp; They run in the session thread so they are not as
      async as people tend to be used to with js. &nbsp; 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. &nbsp;we have discussed doing a
      truly async type control for embedded languages but have never
      implemented it.<span class=""></span>
      <div class=""><br class="">
        On Monday, January 25, 2016, Normando Hall &lt;<a moz-do-not-send="true" href="mailto:nhall@unixlan.com.ar" class=""></a><a class="moz-txt-link-abbreviated" href="mailto:nhall@unixlan.com.ar">nhall@unixlan.com.ar</a>&gt;
        wrote:<br class="">
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor="#FFFFFF" text="#000000" class=""> 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 class="">
            <br class="">
            Thanks!<br class="">
            Normando<br class="">
            <br class="">
            <br class="">
            <div class="">El 25/01/2016 a las 05:59 a.m., Matt Broad escribió:<br class="">
            </div>
            <blockquote type="cite" class="">
              <div dir="ltr" class="">try using the 1 liner sched_broadcast&nbsp;<a moz-do-not-send="true" href="https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast" target="_blank" class=""></a><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>
                <div class=""><br class="">
                </div>
                <div class="">The below will schedule a broadcast to play
                  /tmp/hangupfile.mp3 to both legs after 60 seconds.&nbsp;</div>
                <div class=""><br class="">
                </div>
                <div class=""><i class="">maxTimeTaskID =&nbsp;</i><i class="">session.execute("sched_broadcast",

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

Official FreeSWITCH Sites
<a moz-do-not-send="true" href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a>
<a moz-do-not-send="true" href="http://confluence.freeswitch.org/" target="_blank" class="">http://confluence.freeswitch.org</a>
<a moz-do-not-send="true" href="http://www.cluecon.com/" target="_blank" class="">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" class="">FreeSWITCH-users@lists.freeswitch.org</a>
<a moz-do-not-send="true" href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank" class="">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" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a moz-do-not-send="true" href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a></pre>
            </blockquote>
            <br class="">
          </div>
        </blockquote>
      </div>
      <br class="">
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br class="">
      <pre wrap="" class="">_________________________________________________________________________
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 class="">
  </div>

_________________________________________________________________________<br class="">Professional FreeSWITCH Consulting Services: <br class=""><a href="mailto:consulting@freeswitch.org" class="">consulting@freeswitch.org</a><br class="">http://www.freeswitchsolutions.com<br class=""><br class="">Official FreeSWITCH Sites<br class="">http://www.freeswitch.org<br class="">http://confluence.freeswitch.org<br class="">http://www.cluecon.com<br class=""><br class="">FreeSWITCH-users mailing list<br class="">FreeSWITCH-users@lists.freeswitch.org<br class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users<br class="">UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users<br class="">http://www.freeswitch.org</div></blockquote></div><br class=""></div></body></html>