515439429 发表于 2017-5-18 08:57:43

用perl 语言写freeswitch dialplan

  我建了一个 Freeswitch 内核研究 交流群, 45211986, 欢迎加入, 另外,提供基于SIP的通信服务器及客户端解决方案, 承接 sip/ims 视频客户端开发,支持接入sip软交换,ims核心网,支持 语音,视频,即时通信功能,视频格式支持 h263,h264,mpeg4
软编软解,提供硬件编解码接口对接,提供服务器,有兴趣请联系我。

  

  freeswtich支持 lua, perl, php等脚本语言编写dialplan, 类似asterisk 里面的agi,但freeswitch 更轻量级,其xml格式dialplan 手写确实麻烦,mod_perl实现了用
  perl写dialplan的接口,也就是说我们可以用perl调用freeswich提供的api编写自己的业务逻辑,尤其是当你想
  在dialplan里面引入业务相关的,比如查询数据库,与第三方业务平台交互数据(json,xml格式等),用perl是个不错的选择。
  

  方法:
  1. 在xml dialplan里调用perl 脚本
  创建文件 dialplan/default/demo_perl.pl
  

  内容:
  被叫号是4001时执行此流程,功能是给用户播放一个语音文件,然后验证设置并获取通道变量api.

<include>
<extension name="perl_demo">
<condition field="destination_number" expression="^4001$">
<action application="answer"/>
<action application="perl" data="demo_perl.pl" />
</condition>
</extension>
</include>


app perl 为mod_perl提供的api,执行 demo_perl.pl脚本  

  下面看此文件内容:
  


#!/usr/bin/perl
use strict;
our $session;

freeswitch::console_log("info", "Perl dialplan demo\n");
my ($string) = @_;
#print "\n\n".Dumper(\@_)."\n\n";
my $id = $session->get_uuid();
freeswitch::console_log("info", " uuid $id\n");

#### set and get variable
$session->setVariable("lidp_name", "lidp");
my $name = $session->getVariable("lidp_name");
freeswitch::console_log("info", " lidp_name = $name\n");
$session->execute("playback", "/var/lib/asterisk/moh/macroform-cold_day.wav");
$session->hangup();

return 1;


如果想知道 mod_perl提供了那些函数,可以用这个命令列出来:  


grep -o -P "^(\*[^=]+|############# Class.+)" freeswitch.pm
  

  完。。。。
  

  

  

  

  
页: [1]
查看完整版本: 用perl 语言写freeswitch dialplan