[Freeswitch-users] Problem accessing channel variables

Richard Gration richgration at gmail.com
Thu Nov 29 22:23:22 MSK 2012


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



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