[Freeswitch-users] Problem accessing channel variables

Steven Ayre steveayre at gmail.com
Thu Nov 29 22:43:25 MSK 2012


In this case just receiving events until yours arrives is good enough. A
regex for the UUID is

My suggestion of select/poll/etc would be for a script using a single
connection to start multiple calls, where you'd need to multiplex between
detecting start call events (timeout/dbrow/etc) and incoming events. Since
you're not sending anything else just receiving events works fine.

It's be better to parse events and check the Unique-ID header, but a simple
regex would work. It'd fail in cases like where calls are bridged (the uuid
will appear in events of both call legs) but in this case there's only one
leg so that's probably going to be good enough.

As an optimisation, since you already know the UUID and only watch a single
one on the connection you can use the 'myevents <uuid>' command - that'll
limit it to only events for that channel, so you'll no longer waste
processing on events for other channels and no longer need to check the
uuid in the event.

Since you're still always waiting for CHANNEL_HANGUP and assuming you still
have the ESL connection up, does the variable you're looking appear in the
hangup event? If so perhaps CDR isn't needed.

The wait for the CHANNEL_HANGUP event isn't strictly speaking required, you
could also poll the DB. But waiting for CHANNEL_HANGUP will have the
advantage of not checking the DB until it expects the CDR to be available.

Since


On 29 November 2012 19:23, Richard Gration <richgration at gmail.com> wrote:

> Hi Steve,
>
> Thanks for all your help, I have working code now :-)
>
> I don't know if this is a local configuration "feature" but the events
> are returned synchronously from the "event plain CHANNEL_HANGUP" call,
> so I just loop looking for my uuid.
>
> Cheers,
> Rich
>
> PS For anyone interested in some alpha code ...
>
> $dExt = $_GET['dExt'];
> $pin = $_GET['pin'];
>
> if ($dExt and $pin) {
>     $fp = event_socket_create($host, $port, $password);
>
>     # How shall we abuse the callee today?
>     $wav1 = 'ivr/32000/ivr-douche_telecom.wav';
>     $wav2 = 'ivr/32000/ivr-thank_you_for_calling.wav';
>
>     # Place call and find uuid
>     $cmd = "api originate
> {ignore_early_media=true,originate_timeout=30}sofia/external/677${dExt}@MGC
> '&play_and_get_digits(4 9 1 10000 # $wav1 $wav2 foo \d+)'";
>     $response = event_socket_request($fp, $cmd);
>     $response = strip_cr($response);
>     $bits = preg_split('/\s+/',$response);
>     $uuid = $bits[1];
>
>     $continue = 1;
>     $cmd = "event plain CHANNEL_HANGUP";
>     while ($continue) {
>         error_log("running $cmd");
>         $response = event_socket_request($fp, $cmd);
>         error_log("got $response");
>         if (preg_match("/$uuid/",$response)) {
>             $continue = 0;
>         }
>     }
>
>     $dbhRo = DbConnect::GetConnection('db-readonly');
>     $res_struct = mysql_query("SELECT strSrcMedia FROM cdr WHERE
> strSipSessionId = '$uuid'",$dbhRo);
>     $res = mysql_fetch_array($res_struct);
>     $pin_from_user = $res[0];
>     $result = $pin == $pin_from_user ? 1 : 0 ;
>
>     echo "<pre>";
>     echo date('H:i:s') . "\n";
>     echo "uuid = $uuid\n";
>     echo "$result\n";
>     echo "</pre>";
>
>     # Close socket
>     fclose($fp);
> } else {
>     echo -1;
> }
>
>
> On 29 November 2012 13:56, Steven Ayre <steveayre at gmail.com> wrote:
> >> ... how I listen for these events. Is it just a case of polling the
> >> socket for them at frequent enough intervals?
> >
> >
> > You subscribe to the events you're interested in with 'events'
> > http://wiki.freeswitch.org/wiki/Event_socket#event
> >
> > There's no polling involved. FS will send all subscribed events through
> the
> > socket, you just need to receive them. Use select()/poll()/equivalent to
> > detect when data has arrived.
> >
> > Since you already have xml_cdr working that would be the best place to
> > collect it, if you can add an extra DB insert in the handler.
> >
> > -Steve
> >
> >
> > On 29 November 2012 11:58, Richard Gration <richgration at gmail.com>
> wrote:
> >>
> >> Hi,
> >>
> >> Thanks for your reply. I was wondering ...
> >>
> >> > If you listen to events then you should be able to reliably receive a
> >> > hangup
> >> > event containing the variables if you are still connected at that
> time.
> >>
> >> ... how I listen for these events. Is it just a case of polling the
> >> socket for them at frequent enough intervals?
> >>
> >> > If you want a 100% reliable method use CDRs.
> >> >
> >> > mod_xml_cdr can submit call CDRs to a webserver just after call
> hangup.
> >> > The
> >> > XML is verbose and will contain a full call history and all channel
> >> > variables. Because it's submitted ASAP you get the results in real
> time
> >> > and
> >> > reliable. If the module can't submit the CDRs it writes them to an
> error
> >> > folder on disk where you can resubmit them.
> >> >
> >> > Real time seems useful for your use-case, as your script would just
> need
> >> > to
> >> > check your DB whether the CDR had been submitted yet. The channel UUID
> >> > can
> >> > either be captured from events or specified in advance in the
> originate
> >> > (originate_uuid). There's a uuid api call to generate them for you.
> I'd
> >> > suggest looking at this method.
> >>
> >> This is all great info, thanks :-) I'm capturing the uuid from the
> >> response from the originate command, that's no problem.
> >>
> >> The box I'm doing this on is being a B2BUA for us at the moment. The
> >> CDRs are already being HTTP POSTed to a URL, I can't change that as
> >> our billing depends on it. I can see the channel variable coming
> >> though in the POST content, so maybe I can frob the CDR script to give
> >> me what I want.
> >>
> >> Thanks again for the info.
> >>
> >> Cheers,
> >> Rich
> >>
> >> --
> >> Once our basic material needs are met - in my utopia, anyway - life
> >> becomes a perpetual celebration in which everyone has a talent to
> >> contribute. But we cannot levitate ourselves into that blessed
> >> condition by wishing it. We need to brace ourselves for a struggle
> >> against terrifying obstacles, both of our own making and imposed by
> >> the natural world. And the first step is to recover from the delusion
> >> that is positive thinking.
> >>        -- Barbara Ehrenreich
> >>
> >>
> _________________________________________________________________________
> >> Professional FreeSWITCH Consulting Services:
> >> consulting at freeswitch.org
> >> http://www.freeswitchsolutions.com
> >>
> >> 
> >> 
> >>
> >> Official FreeSWITCH Sites
> >> http://www.freeswitch.org
> >> http://wiki.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://wiki.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
> >
>
>
>
> --
> Once our basic material needs are met - in my utopia, anyway - life
> becomes a perpetual celebration in which everyone has a talent to
> contribute. But we cannot levitate ourselves into that blessed
> condition by wishing it. We need to brace ourselves for a struggle
> against terrifying obstacles, both of our own making and imposed by
> the natural world. And the first step is to recover from the delusion
> that is positive thinking.
>        -- Barbara Ehrenreich
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.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/20121129/4e502ded/attachment-0001.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list