You might get a more scalable result with this in test.js and get rid of inc.js completely.session:execute("sched_transfer", "+5 playback:/sounds/en/us/callie/test.wav,hangup inline");--On Tue, Jan 26, 2016 at 2:44 PM, Michael Jerris <mike@jerris.com> wrote:If its in park thats one thing, if you are doing ANYTHING to the channel, you have potential concurrency issues, if you are doing anything with audio from different threads, nothing good will come from it. As for another possible solution to the original problem, you could sched_api and uuid_transfer to a different extension that played what you needed to play and then hung up too.On Jan 26, 2016, at 3:37 PM, Matt Broad <matt@supportedbusiness.com> wrote::/I only came across this method after trying to get the sched_broadcast to not block. An answer from Anthony on the 17th Sept 2015 (shown below) gave me the idea, though I have never implemented it into anything other than test code."uuid_broadcast does not block.The problem is you are calling it from your js app which is occupying the session thread.To perform async operation you need to run your script outside the session thread by calling the script via the api interface via jsrun and pass the uuid then put the channel into park or use an esl script to control the session externally."I must admit the inner workings of the session thread is not something I have looked into personally (one day maybe).If you could give me a quick explanation as to why this wouldn't work that would be appreciated :)ThanksMatt_________________________________________________________________________On 26 January 2016 at 17:09, Michael Jerris <mike@jerris.com> wrote:This isn't supposed to work.. and might cause crashes.On Jan 26, 2016, at 10:18 AM, Matt Broad <matt@supportedbusiness.com> wrote:works fine for me :)DialPlan<condition field="destination_number" expression="^1234$"><action application="answer" /><action application="javascript" data="test.js" /></condition>test.jsresult = apiExecute("sched_api","+5 "+session.uuid+" jsrun /scripts/inc.js "+session.uuid);console_log("notice", "entering loop\n");while (session.ready()){//sit here whilst the call is still connected}console_log("notice", "call ended\n");inc.jsinclude("includes/General.js"); //this includes a function "Output" to log to screenvar session = new Session(argv[0]);if (session.ready()) {Output("TIMEOUT");session.execute("playback", "/sounds/en/us/callie/test.wav");session.execute("sleep","500");session.hangup();}exit("TIMEOUT");ThanksMatt_________________________________________________________________________On 26 January 2016 at 14:43, Michael Jerris <mike@jerris.com> wrote:this won't actually work. You can't session execute from outside the session thread like this.
On Tuesday, January 26, 2016, Matt Broad <matt@supportedbusiness.com> wrote:Hi Normando,from your description I assumed you were just trying to schedule a file to play and hang up.If you are trying to run a block of code at a certain time in the future then you could use sched_api. https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-sched_api This will execute an API command after a given time. In your case you could use the API command jsrun to run a script containing your function.An example would be:result = apiExecute("sched_api","120 "+session.uuid+" jsrun /scripts/function.js "+session.uuid+" "+despedida);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 despedida variable.Within the function.js file, you can create a session object using the uuid passed through and then use this to play the file etce.g of function.jsvar session = new Session(argv[0]);var despedida = argv[1];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");thanksMattOn 25 January 2016 at 22:11, Michael Jerris <mike@jerris.com> wrote: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.\MikeOn Jan 25, 2016, at 4:24 PM, Normando Hall <nhall@unixlan.com.ar> wrote:Hi Michael._________________________________________________________________________
Yes, you are right, maybe the better is to use ESL.
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.
I workaround this with:
session.collectInput(onPlay, services, afterMenuTimeOut, totalTimeOut);
playTimeout(despedida)
and return always "true" from "onPlay" callback.
Respond to your question, this is the function I want to run in setTimeout:
function playTimeout(despedida){
if (session.ready()) {
logger("TIMEOUT");
session.execute("sleep","400");
session.execute("playback", sonidos + "/TIMEOUT.wav");
session.execute("sleep","400");
logger(despedida);
session.execute("playback", sonidos + "/" + despedida + ".wav");
session.hangup();
}
exit("TIMEOUT");
}
Thanks
Normando
El 25/01/2016 a las 05:20 p.m., Michael Jerris escribió:
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@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
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.
thanksMatt
On 25 January 2016 at 06:58, <royj@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@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@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.orgAnthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬ClueCon Weekly Development Call
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@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@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org