如何在Freeswitch中检测挂断事件?

时间:2019-07-19 06:50:31

标签: perl voip freeswitch

我是Freeswitch的新手,正在寻求专家的帮助。我的问题在下面。

我正在尝试在Perl中的以下情况下进行操作:

当我接到脚本(test.pl的来电时,我向其中播放文件,然后将入站会话置于保留状态。然后,我尝试使用单独的脚本(test2.pl)进行新的出站会话。如果出站呼叫得到应答,则我break处于保持状态的入站会话,bridge都是两个会话。脚本如下。

test.pl

use strict;
use warnings;

our $session;

if( $session->ready() ) {
    $session->setVariable( 'hangup_after_bridge', 'false' );
    $session->setVariable( 'continue_on_fail', 'true' );
    $session->answer();

    my $api = new freeswitch::API;
    $api->execute('perlrun', '/usr/share/freeswitch/scripts/test2.pl ' . $session->get_uuid());
    $session->setVariable('playback_timeout_sec', '70');
    $session->execute("playback", '$${hold_music}');

    if ($session->getVariable('outbound_answered') == 'true') {
        my $outbound_uuid = $session->getVariable('outbound_uuid');
        my $outbound_session = new freeswitch::Session($outbound_uuid);

        if ($outbound_session->ready()) {
            $session->bridge($outbound_session);
        } else {
            # outbound session disconnected.
        }
    }  else {
        # outbound session didn't answer.
    }
} else {
    # Inbound disconneected.
}
1;

test2.pl

use strict;
use warnings;

my $api = new freeswitch::API;
my $inbound_uuid = $ARGV[0];
my $inbound_session = new freeswitch::Session( $inbound_uuid );

my $originate_str = "sofia/gateway/outbound/0416661666";
my $outbound_session = new freeswitch::Session( $originate_str );
my $hangup_cause_out = $outbound_session->hangupCause();
$inbound_session->setVariable( 'outbound_uuid', $outbound_session->get_uuid() );

if ( $outbound_session->ready() ) {
    if ( $inbound_session->ready() ) {
        $inbound_session->setVariable('outbound_answered', 'true');
        $outbound_session->streamFile("/usr/share/freeswitch/sounds/en/us/callie/ivr/8000/ivr-please_hold_while_party_contacted.wav");
        $inbound_session->execute('break');
        while ($inbound_session->ready()) {
            sleep(10);
            # Inbound sessnio ok, continue outbound session.
        }
    } else {
        # Inbound session got disconnected while we trying outbound.
    }
} else {
    # Outbound call failed.
}
1;

Debian系统日志:

Jul 19 13:14:50 XXX systemd[1]: freeswitch.service: Main process exited, code=killed, status=6/ABRT
Jul 19 13:14:50 XXX systemd[1]: freeswitch.service: Unit entered failed state.
Jul 19 13:14:50 XXX systemd[1]: freeswitch.service: Failed with result 'signal'.
Jul 19 13:14:50 XXX systemd[1]: freeswitch.service: Service hold-off time over, scheduling restart.
Jul 19 13:14:50 XXX systemd[1]: Stopped freeswitch.
Jul 19 13:14:50 XXX systemd[1]: Starting freeswitch...

预期的方案可以正常工作。但是我的问题是,当Freeswitch振铃出站方时,来话呼叫方挂断入站会话时,Freeswitch会重新启动。 更新: 我还注意到,如果出站未接听电话,则10秒钟后也会发生同样的事情。

我认为我需要处理入站会话挂断事件,但在这里有点失败。可能是我做错了。

正在寻找Freeswitch专家的建议。

谢谢!

0 个答案:

没有答案