[Freeswitch-users] System global mode variable

Steven Ayre steveayre at gmail.com
Fri Jun 10 15:56:45 MSD 2016


Are you planning to change this at runtime? I seem to remember a post on
the mailing list from very long time ago (years) changing global variables
that were being read at the same time had a small risk of a race condition
that might segfault.

If so that has almost certainly been fixed by now, but if not you could
also look at using mod_hash or mod_db.

Your simple script can be done in xml by the way without lua using inline
api calls in the condition's field attributes. Entirely personal preference
which you use. Lua will fetch the variable just once so dies have that
advantage.





On Thursday, 9 June 2016, Pete Ashdown <pashdown at xmission.com> wrote:

> Answered my own question:
>
> In your dialplan:
> <action application="lua" data="script.lua"/>
>
> In script.lua:
> mode = freeswitch.getGlobalVariable("mode")
> if (mode == "open") then
>   session:speak("open")
> end
> if (mode == "techonly") then
>   session:speak("teck only")
> end
> if (mode == "event") then
>   session:speak("event")
> else
>   session:speak("i dont know")
> end
>
> Make sure the global is created somewhere, like vars.xml:
> <X-PRE-PROCESS cmd="set" data="mode=open"/>
>
>
> On 06/07/2016 08:50 AM, Pete Ashdown wrote:
> > What is the simplest way to have a conditional branch based on a global
> > variable in a dialplan?  Actually using a global variable and xml is
> > giving me mixed results.  Do I need to use Lua or another scripting
> > language?
> >
> > This is what I have, which doesn't give the results desired.   The
> > "speak" actions are merely debug placeholders.  I know there are better
> > ways to do conditional voice to text.
> >
> >       <condition regex="any" field="${cond(${mode} == 'open' ? YES :
> > NO)}" expression="^YES$">
> >             <action application="speak" data="open"/>
> >       </condition>
> >
> >       <condition regex="any" field="${cond(${mode} == 'tech only' ? YES
> > : NO)}" expression="^YES$">
> >             <action application="speak" data="teck only"/>
> >       </condition>
> >
> >       <condition regex="any" field="${cond(${mode} == 'event' ? YES :
> > NO)}" expression="^YES$">
> >             <action application="speak" data="event"/>
> >       </condition>
> >
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org <javascript:;>
> 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 <javascript:;>
> 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/20160610/5e858b6f/attachment.html 


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