<div dir="ltr">works fine for me :)<div><br></div><div><b>DialPlan</b></div><div><div> <condition field="destination_number" expression="^1234$"></div><div> <action application="answer" /></div><div> <action application="javascript" data="test.js" /></div></div><div></condition><br></div><div><br></div><div><br></div><div><b>test.js</b></div><div><div>result = apiExecute("sched_api","+5 "+session.uuid+" jsrun /scripts/inc.js "+session.uuid);</div><div>console_log("notice", "entering loop\n");</div><div>while (session.ready())</div><div>{</div><div> //sit here whilst the call is still connected </div><div>}</div><div>console_log("notice", "call ended\n");</div></div><div><br></div><div><br></div><div><b>inc.js</b><br></div><div><div>include("includes/General.js"); //this includes a function "Output" to log to screen<br></div><div><br></div><div>var session = new Session(argv[0]);</div><div><br></div><div>if (session.ready()) {</div><div> Output("TIMEOUT");</div><div> session.execute("playback", "/sounds/en/us/callie/test.wav");</div><div> session.execute("sleep","500");</div><div> session.hangup();</div><div>}</div><div>exit("TIMEOUT");</div></div><div><br></div><div><br></div><div>Thanks</div><div>Matt</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 January 2016 at 14:43, Michael Jerris <span dir="ltr"><<a href="mailto:mike@jerris.com" target="_blank">mike@jerris.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">this won't actually work. You can't session execute from outside the session thread like this.<div class="HOEnZb"><div class="h5"><span></span><br><br>On Tuesday, January 26, 2016, Matt Broad <<a href="mailto:matt@supportedbusiness.com" target="_blank">matt@supportedbusiness.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Normando,<div><br></div><div>from your description I assumed you were just trying to schedule a file to play and hang up.</div><div> </div><div>If you are trying to run a block of code at a certain time in the future then you could use sched_api. <a href="https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-sched_api" target="_blank">https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-sched_api</a> This will execute an API command after a given time. In your case you could use the API command <b>jsrun</b> to run a script containing your function.</div><div><br></div><div>An example would be:</div><div><br></div><div><i>result = apiExecute("sched_api","120 "+session.uuid+" jsrun /scripts/function.js "+session.uuid+" "+<span style="font-size:12.8px">despedida</span>);</i></div><div><br></div><div><br></div><div>The above will execute jsrun after 120 seconds (this is linked to the session.uuid so if the channel is destroyed the task will be removed automatically). This will run the function.js file and pass it the current session uuid along with the <span style="font-size:12.8px">despedida variable</span>. </div><div>Within the function.js file, you can create a session object using the uuid passed through and then use this to play the file etc</div><div><br></div><div>e.g of function.js</div><div><br></div><div>var session = new Session(argv[0]);</div><div>var <span style="font-size:12.8px">despedida = argv[1];</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">if (session.ready()) {</span><br></div><div><span style="font-size:12.8px"> logger("TIMEOUT");</span><br style="font-size:12.8px"><span style="font-size:12.8px"> session.execute("playback", sonidos + "/TIMEOUT.wav");</span><br style="font-size:12.8px"><span style="font-size:12.8px"> session.execute("sleep","500")</span><span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> logger(despedida);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> session.execute("playback", sonidos + "/" + despedida + ".wav");</span><br style="font-size:12.8px"><span style="font-size:12.8px"> session.hangup();</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><span style="font-size:12.8px">exit("TIMEOUT");</span><br style="font-size:12.8px"><br style="font-size:12.8px"></div><div><br></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 22:11, Michael Jerris <span dir="ltr"><<a>mike@jerris.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"> 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. A note, you might want to look at phrase macros as they will greatly simplify some of that code as well.\<div>Mike</div><div><div><div><br><div><blockquote type="cite"><div>On Jan 25, 2016, at 4:24 PM, Normando Hall <<a>nhall@unixlan.com.ar</a>> wrote:</div><br><div>
<div 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>El 25/01/2016 a las 05:20 p.m., Michael
Jerris escribió:<br>
</div>
<blockquote 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 <<a></a><a>nhall@unixlan.com.ar</a>>
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 href="https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast" target="_blank"></a><a href="https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast" target="_blank">https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast</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"><<a>royj@yandex.ru</a>></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 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" <<a></a><a>nhall@unixlan.com.ar</a>>:<br>
<div>
<div>> Sorry, I missed to say it is Freeswitch
1.4<br>
><br>
> El 25/01/2016 a las 02:53 a.m., Normando
Hall escribió:<br>
>> Hello everybody.<br>
>><br>
>> I am coding a js script to do
somethings, and I want to add a global<br>
>> timeout, to call a function to play a
file and hangup. But the function<br>
>> called inmediatelly.<br>
>> Also tested with setInterval, the same
behaviour.<br>
>><br>
>> function playTimeout(despedida){<br>
>> if (session.ready()) {<br>
>> logger("TIMEOUT");<br>
>> session.execute("playback",
sonidos + "/TIMEOUT.wav");<br>
>>
session.execute("sleep","500");<br>
>> logger(despedida);<br>
>> session.execute("playback",
sonidos + "/" + despedida + ".wav");<br>
>> session.hangup();<br>
>> }<br>
>> exit("TIMEOUT");<br>
>> }<br>
>><br>
>>
setTimeout(playTimeout(despedida),120000);<br>
>> .<br>
>> .<br>
>> .<br>
>> my script continue<br>
>><br>
>> Any help is welcome!<br>
>><br>
>> Thank you<br>
>> Normando<br>
>><br>
>>
_________________________________________________________________________<br>
>> Professional FreeSWITCH Consulting
Services:<br>
>> <a>consulting@freeswitch.org</a><br>
>> <a href="http://www.freeswitchsolutions.com/" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
>><br>
>> Official FreeSWITCH Sites<br>
>> <a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
>> <a href="http://confluence.freeswitch.org/" rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
>> <a href="http://www.cluecon.com/" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
>><br>
>> FreeSWITCH-users mailing list<br>
>> <a>FreeSWITCH-users@lists.freeswitch.org</a><br>
>> <a 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 href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
>> <a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
><br>
>
_________________________________________________________________________<br>
> Professional FreeSWITCH Consulting
Services:<br>
> <a>consulting@freeswitch.org</a><br>
> <a href="http://www.freeswitchsolutions.com/" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
><br>
> Official FreeSWITCH Sites<br>
> <a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
> <a href="http://confluence.freeswitch.org/" rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
> <a href="http://www.cluecon.com/" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
><br>
> FreeSWITCH-users mailing list<br>
> <a>FreeSWITCH-users@lists.freeswitch.org</a><br>
> <a 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 href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
> <a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a>consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com/" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org/" rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com/" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a>FreeSWITCH-users@lists.freeswitch.org</a><br>
<a 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 href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a 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>consulting@freeswitch.org</a>
<a href="http://www.freeswitchsolutions.com/" target="_blank">http://www.freeswitchsolutions.com</a>
Official FreeSWITCH Sites
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a>
<a href="http://confluence.freeswitch.org/" target="_blank">http://confluence.freeswitch.org</a>
<a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com</a>
FreeSWITCH-users mailing list
<a>FreeSWITCH-users@lists.freeswitch.org</a>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a></pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
<a>consulting@freeswitch.org</a>
<a href="http://www.freeswitchsolutions.com/" target="_blank">http://www.freeswitchsolutions.com</a>
Official FreeSWITCH Sites
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a>
<a href="http://confluence.freeswitch.org/" target="_blank">http://confluence.freeswitch.org</a>
<a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com</a>
FreeSWITCH-users mailing list
<a>FreeSWITCH-users@lists.freeswitch.org</a>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a></pre>
</blockquote>
<br>
</div>
_________________________________________________________________________<br>Professional FreeSWITCH Consulting Services: <br><a>consulting@freeswitch.org</a><br><a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br><br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br><a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br><a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br><br>FreeSWITCH-users mailing list<br><a>FreeSWITCH-users@lists.freeswitch.org</a><br><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></div></blockquote></div><br></div></div></div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a>consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a>FreeSWITCH-users@lists.freeswitch.org</a><br>
<a 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 href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>
</blockquote>
</div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" rel="noreferrer" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a 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 href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>