mod_event_socket以socket的形式,对外提供控制FS一种途径, 缺省的IP是127.0.0.1,TCP端口是8021,可以在外部通过sokcet执行API/APP命令。
ESL 通信类型
连接分两种模式: inbound/outbound
mod_event_socket 的默认加载模式是inbound,outbound模式需要在dialplan的配置文件中设置。
Inbound 就是 FreeSwitch 作为 server,而使用方采用 esl 写的程序是 client.
Outbound 就是 esl 写的程序是 server,而 FreeSwitch 是 client
inbound/outbound 是站在fs的角度来看的,外部应用连进来,就是inbound;fs连出去,就是outbound。
sockert 配置 在freeswitch/autoload_configs目录中的event_socket.conf.xml
# cat event_socket.conf.xml<configuration name="event_socket.conf" description="Socket Client"><settings><param name="nat-map" value="false"/><param name="listen-ip" value="0.0.0.0"/><param name="listen-port" value="$${FS_EVENT_PORT}"/><param name="password" value="$${FS_EVENT_PASSWORD}"/><!--<param name="apply-inbound-acl" value="loopback.auto"/>--><!--<param name="stop-on-bind-error" value="true"/>--></settings></configuration>
ESL 消息类型
在 event_socket.c 中定义为
static const char *format2str(event_format_t format){switch (format) {case EVENT_FORMAT_PLAIN:return "plain";case EVENT_FORMAT_XML:return "xml";case EVENT_FORMAT_JSON:return "json";}return "invalid";}
设置账号密码和端口 /conf/autoload_configs/event_socket.conf.xml
<configuration name="event_socket.conf" description="Socket Client"><settings><param name="nat-map" value="false"/><param name="listen-ip" value="0.0.0.0"/><param name="listen-port" value="8021"/><param name="password" value="123456"/><!-- <param name="apply-inbound-acl" value="lan"/>--><param name="apply-inbound-acl" value="loopback.auto"/><!--<param name="stop-on-bind-error" value="true"/>--></settings></configuration>
设置loopback访问规则: /conf/autoload_configs/acl.conf.xml
<configuration name="acl.conf" description="Network Lists"><network-lists><!--These ACL's are automatically created on startup.rfc1918.auto - RFC1918 Spacenat.auto - RFC1918 Excluding your local lan.localnet.auto - ACL for your local lan.loopback.auto - ACL for your local lan.--><list name="loopback.auto" default="allow"><node type="allow" host="0.0.0.0" mask="0.0.0.0" /></list><list name="lan" default="allow"><node type="deny" cidr="192.168.42.0/24"/><node type="allow" cidr="192.168.42.42/32"/></list><!--This will traverse the directory adding all userswith the cidr= tag to this ACL, when this ACL matchesthe users variables and params apply as if theydigest authenticated.--><list name="domains" default="deny"><!-- domain= is special it scans the domain from the directory to build the ACL --><node type="allow" domain="$${domain}"/><!-- use cidr= if you wish to allow ip ranges to this domains acl. --><!-- <node type="allow" cidr="192.168.0.0/24"/> --></list></network-lists></configuration>
# fs_cli -x "reloadacl"+OK acl reloaded
加载配置
# fs_cli -x "reloadacl"+OK acl reloaded
参考
https://cloud.tencent.com/developer/inventory/9113/article/1585511
https://blog.csdn.net/Coolyqq/article/details/49760481
https://freeswitch.org/confluence/display/FREESWITCH/Event+Socket+Library
https://blog.csdn.net/xuyunzhang/article/details/28097929
