[Freeswitch-users] Issue with Javascript setTimeout

Matt Broad matt at supportedbusiness.com
Tue Jan 26 00:16:26 MSK 2016


the sched_broadcast with the hangup parameter should work fine, I use it in
a few js projects :)

The function is replaced by the sched_broadcast, so going by your example
you would have:

//set up the play file and hangup
*session.execute("sched_broadcast", "+120 playback!normal_clearing::"
+ *sonidos
+ "/" + despedida + ".wav* both")*;

...
...
...
*script continues*


After 120 seconds, the sonidos/despedida.wav file will be played and then
the call will end with the  "normal_clearing" (16) cause code.
During the 120 seconds, you can run any other code you need.  If the call
ends before the 120 seconds, the broadcast is automatically disposed of.

thanks
Matt

On 25 January 2016 at 20:20, Michael Jerris <mike at jerris.com> wrote:

> 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.
>
> On Monday, January 25, 2016, Normando Hall <nhall at unixlan.com.ar> wrote:
>
>> 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?
>>
>> Thanks!
>> Normando
>>
>>
>> El 25/01/2016 a las 05:59 a.m., Matt Broad escribió:
>>
>> try using the 1 liner sched_broadcast
>> <https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast>
>> https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+sched+broadcast
>>
>> The below will schedule a broadcast to play /tmp/hangupfile.mp3 to both
>> legs after 60 seconds.
>>
>> *maxTimeTaskID = **session.execute("sched_broadcast", "+60
>> playback!normal_clearing::/tmp/hangupfile.mp3 both")*;
>>
>> If you find you need to cancel the broadcast use:
>>
>> *session.execute("sched_cancel",maxTimeTaskID);*
>>
>> hope this helps.
>>
>> thanks
>> Matt
>>
>> On 25 January 2016 at 06:58, <royj at yandex.ru> wrote:
>>
>>> have no relationship to the resource, but first link to request
>>> 'asynchronous code javascript'
>>>
>>>
>>> http://www.hiddenwebgenius.com/blog/guides/understanding-javascripts-asynchronous-code/
>>>
>>> 25.01.2016, 09:16, "Normando Hall" <nhall at unixlan.com.ar>:
>>> > Sorry, I missed to say it is Freeswitch 1.4
>>> >
>>> > El 25/01/2016 a las 02:53 a.m., Normando Hall escribió:
>>> >>  Hello everybody.
>>> >>
>>> >>  I am coding a js script to do somethings, and I want to add a global
>>> >>  timeout, to call a function to play a file and hangup. But the
>>> function
>>> >>  called inmediatelly.
>>> >>  Also tested with setInterval, the same behaviour.
>>> >>
>>> >>  function playTimeout(despedida){
>>> >>      if (session.ready()) {
>>> >>          logger("TIMEOUT");
>>> >>          session.execute("playback", sonidos + "/TIMEOUT.wav");
>>> >>          session.execute("sleep","500");
>>> >>          logger(despedida);
>>> >>          session.execute("playback", sonidos + "/" + despedida +
>>> ".wav");
>>> >>          session.hangup();
>>> >>      }
>>> >>      exit("TIMEOUT");
>>> >>  }
>>> >>
>>> >>  setTimeout(playTimeout(despedida),120000);
>>> >>  .
>>> >>  .
>>> >>  .
>>> >>  my script continue
>>> >>
>>> >>  Any help is welcome!
>>> >>
>>> >>  Thank you
>>> >>  Normando
>>> >>
>>> >>
>>>  _________________________________________________________________________
>>> >>  Professional FreeSWITCH Consulting Services:
>>> >>  consulting at freeswitch.org
>>> >>  http://www.freeswitchsolutions.com
>>> >>
>>> >>  Official FreeSWITCH Sites
>>> >>  http://www.freeswitch.org
>>> >>  http://confluence.freeswitch.org
>>> >>  http://www.cluecon.com
>>> >>
>>> >>  FreeSWITCH-users mailing list
>>> >>  FreeSWITCH-users at lists.freeswitch.org
>>> >>  http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>>> >>  UNSUBSCRIBE:
>>> http://lists.freeswitch.org/mailman/options/freeswitch-users
>>> >>  http://www.freeswitch.org
>>> >
>>> >
>>> _________________________________________________________________________
>>> > Professional FreeSWITCH Consulting Services:
>>> > consulting at freeswitch.org
>>> > http://www.freeswitchsolutions.com
>>> >
>>> > Official FreeSWITCH Sites
>>> > http://www.freeswitch.org
>>> > http://confluence.freeswitch.org
>>> > http://www.cluecon.com
>>> >
>>> > FreeSWITCH-users mailing list
>>> > FreeSWITCH-users at lists.freeswitch.org
>>> > http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>>> > UNSUBSCRIBE:
>>> http://lists.freeswitch.org/mailman/options/freeswitch-users
>>> > http://www.freeswitch.org
>>>
>>> _________________________________________________________________________
>>> Professional FreeSWITCH Consulting Services:
>>> consulting at freeswitch.org
>>> http://www.freeswitchsolutions.com
>>>
>>> Official FreeSWITCH Sites
>>> http://www.freeswitch.org
>>> http://confluence.freeswitch.org
>>> http://www.cluecon.com
>>>
>>> FreeSWITCH-users mailing list
>>> FreeSWITCH-users at lists.freeswitch.org
>>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>>> http://www.freeswitch.org
>>>
>>
>>
>>
>> _________________________________________________________________________
>> Professional FreeSWITCH Consulting Services: consulting at freeswitch.orghttp://www.freeswitchsolutions.com
>>
>> Official FreeSWITCH Siteshttp://www.freeswitch.orghttp://confluence.freeswitch.orghttp://www.cluecon.com
>>
>> FreeSWITCH-users mailing listFreeSWITCH-users at lists.freeswitch.orghttp://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-usershttp://www.freeswitch.org
>>
>>
>>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20160125/2c457fe5/attachment.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list