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

  1. # cat event_socket.conf.xml
  2. <configuration name="event_socket.conf" description="Socket Client">
  3. <settings>
  4. <param name="nat-map" value="false"/>
  5. <param name="listen-ip" value="0.0.0.0"/>
  6. <param name="listen-port" value="$${FS_EVENT_PORT}"/>
  7. <param name="password" value="$${FS_EVENT_PASSWORD}"/>
  8. <!--<param name="apply-inbound-acl" value="loopback.auto"/>-->
  9. <!--<param name="stop-on-bind-error" value="true"/>-->
  10. </settings>
  11. </configuration>

ESL 消息类型

在 event_socket.c 中定义为

  1. static const char *format2str(event_format_t format)
  2. {
  3. switch (format) {
  4. case EVENT_FORMAT_PLAIN:
  5. return "plain";
  6. case EVENT_FORMAT_XML:
  7. return "xml";
  8. case EVENT_FORMAT_JSON:
  9. return "json";
  10. }
  11. return "invalid";
  12. }

设置账号密码和端口 /conf/autoload_configs/event_socket.conf.xml

  1. <configuration name="event_socket.conf" description="Socket Client">
  2. <settings>
  3. <param name="nat-map" value="false"/>
  4. <param name="listen-ip" value="0.0.0.0"/>
  5. <param name="listen-port" value="8021"/>
  6. <param name="password" value="123456"/>
  7. <!-- <param name="apply-inbound-acl" value="lan"/>-->
  8. <param name="apply-inbound-acl" value="loopback.auto"/>
  9. <!--<param name="stop-on-bind-error" value="true"/>-->
  10. </settings>
  11. </configuration>

设置loopback访问规则: /conf/autoload_configs/acl.conf.xml

  1. <configuration name="acl.conf" description="Network Lists">
  2. <network-lists>
  3. <!--
  4. These ACL's are automatically created on startup.
  5. rfc1918.auto - RFC1918 Space
  6. nat.auto - RFC1918 Excluding your local lan.
  7. localnet.auto - ACL for your local lan.
  8. loopback.auto - ACL for your local lan.
  9. -->
  10. <list name="loopback.auto" default="allow">
  11. <node type="allow" host="0.0.0.0" mask="0.0.0.0" />
  12. </list>
  13. <list name="lan" default="allow">
  14. <node type="deny" cidr="192.168.42.0/24"/>
  15. <node type="allow" cidr="192.168.42.42/32"/>
  16. </list>
  17. <!--
  18. This will traverse the directory adding all users
  19. with the cidr= tag to this ACL, when this ACL matches
  20. the users variables and params apply as if they
  21. digest authenticated.
  22. -->
  23. <list name="domains" default="deny">
  24. <!-- domain= is special it scans the domain from the directory to build the ACL -->
  25. <node type="allow" domain="$${domain}"/>
  26. <!-- use cidr= if you wish to allow ip ranges to this domains acl. -->
  27. <!-- <node type="allow" cidr="192.168.0.0/24"/> -->
  28. </list>
  29. </network-lists>
  30. </configuration>
  1. # fs_cli -x "reloadacl"
  2. +OK acl reloaded

加载配置

  1. # fs_cli -x "reloadacl"
  2. +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