可以通过
<param name="parse-all-invite-headers" value="true"/>
在Sofia SIP Profile中进行设置。然后将来自 Invite 的所有标头设置为sip_i _Header-Name 通道变量。
对任何其他 SIP 消息中的特定 Headear 做出反应:
如果您想对其他消息上的特定标头做出反应,您可以通过设置变量sip_watch_headers来做到这一点(如果您只希望它用于 B-leg,则需要导出并以nolocal为前缀)
如果检测到标头,您将收到子类“sofia::notify_watched_header”的 CUSTOM 事件。
检测B-Leg 上的Reason标头的示例:
<action application="export" data="_nolocal_sip_watch_headers=Reason"/>
这是一个在 B-Leg 上寻找 Reason 标头的 Event 示例,查看标头“Reason”:
"Event-Name": "CUSTOM",
...
"Event-Calling-File": "sofia.c",
"Event-Calling-Function": "notify_watched_header",
"Event-Calling-Line-Number": "1443",
"Event-Sequence": "98672",
"Event-Subclass": "sofia::notify_watched_header",
"SIP-Message": "SIP/2.0 183 Session Progress",
"Header-Name": "Reason",
"Header-Value": "Q.850;cause=16",
"Channel-State": "CS_CONSUME_MEDIA",
"Channel-Call-State": "DOWN",
"Channel-State-Number": "7",
...
"Call-Direction": "outbound",
可以通过在 Lua 配置中设置挂钩脚本或通过 AMQP / EventSocket 对 Lua 做出反应。
如何使用 Lua 对这些事件做出反应
https://freeswitch.org/confluence/display/FREESWITCH/mod_lua#Event_Hooks
示例:autload_configs/lua.conf.xml:
<configuration name="lua.conf" description="LUA Configuration">
<settings>
<param name="module-directory" value="/etc/freeswitch/scripts/?.so"/>
<param name="script-directory" value="/etc/freeswitch/scripts/?.lua"/>
<!--<param name="startup-script" value="startup_script_1.lua"/>--> <!-- started at fs startup and maybe lives forever -->
<hook event="CHANNEL_DESTROY" script="/etc/freeswitch/scripts/on_channel_destroy.lua"/>
<hook event="CUSTOM" subclass="sofia::notify_watched_header" script="/etc/freeswitch/scripts/on_reason_header.lua"/>
</settings>
</configuration>
示例 Lua 脚本
local uuid = event:getHeader("Unique-ID")
local shallHangup = event:getHeader("variable_HangupOnReasonInEarly")
local answerState = event:getHeader("Answer-State")
if (shallHangup ~= nil and shallHangup == "true" and answerState == "ringing") then
local value = event:getHeader("Header-Value")
local code = value:match(";cause=(%d*)")
--local data = event:serialize("json")
freeswitch.consoleLog("INFO","REASON DETECTED: for: " .. uuid .. "\n")
api = freeswitch.API()
api:executeString("uuid_kill " .. uuid .. " " .. code)
end
要在拨号方案中启用它:
<action application="export" data="_nolocal_sip_watch_headers=Reason"/>
<action application="export" data="_nolocal_HangupOnReasonInEarly=true"/>
<action application="bridge" data="..."/>