FreeSWITCH核心命令

FreeSWITCH核心命令

簡介

 

下面的是根據最新的版本r14778(九月九號)中mod_commands模塊提供的命令,這些命令可以使用方式有很多種,如下:

控制檯

具體查看下面內容。 譯者注:通過FreeSWITCH控制檯使用

API/事件 接口

通過API或事件接口調用,如:

  • [[mod_event_socket]]
  • [[mod_xmpp_event]]
  • [[mod_erlang_event]]
  • [[mod_xml_rpc]]

腳本接口

通過腳本進行調用,如下:

  • [[mod_perl]]
  • [[mod_spidermonkey]]
  • [[mod_python]]
  • [[mod_lua]]

撥號方案調用

通過撥號方案進行調用,例子如下:

<source lang="xml">
 <extension name="Make API call from Dialplan">
   <condition field="destination_number" expression="^(999)$">
     <!-- next line calls hupall, so be careful! -->
     <action application="set" data="api_result=${hupall(normal_clearing)}"/>
   </condition>
 </extension>
</source>

其他例子:

<source lang="xml">
 <action application="set" data="api_result=${status()}"/>
 <action application="set" data="api_result=${version()}"/>
 <action application="set" data="api_result=${strftime()}"/>
 <action application="set" data="api_result=${expr(1+1)}"/>
</source>

如果API命令含有多個參數,通常都是以空格隔開。

<source lang="xml">
 <action application="set" data="api_result=${sched_api(+5 none avmd ${uuid} start)}"/>
</source>

API命令依賴於加載的相關模塊,從每個模塊註冊的API命令中都能發現它們的蹤影。

想要查看全部API命令列表的話,在cli中輸入help或者show api即可。

注:如果你想從撥號方案中調用API命令的話,需要先確認撥號方案自帶的dptools裏面沒有類似的命令。

核心命令

主要在http://fisheye.freeswitch.org/browse/freeswitch.git/src/mod/applications/mod_commands/mod_commands.c中實現。

注:一些狀態或列表命令的返回結果默認是以逗號進行分隔的列表。一些模塊的返回結果可能也會包含逗號,這樣就導致針對結果的自動化處理比較困難。一個解決方法是,是在命令的最後加上“as xml”,這樣返回的就是xml格式的結果。

acl

使用acl列表判斷ip地址是否爲合法訪問。

Usage: acl

命令別名alias

別名:一種針對常用命令的快捷輸入方式

用法: alias add <別名> <命令> | del [<別名>|*]

例子:

freeswitch> alias add reloadall reloadacl reloadxml
  +OK
freeswitch> alias add unreg sofia profile internal flush_inbound_reg
  +OK

別名在重啓後需要重設,如果需要重啓後仍然生效,需要使用stickyadd參數,如下:
freeswitch> alias stickyadd reloadall reloadacl reloadxml
  +OK

注:只在mod_console中起作用,在fs_cli中無效。 
譯者注:mod_console爲以前臺模式啓動的freeswitch的命令輸入界面。而fs_cli指的是freeswitch的客戶端。

bgapi

用於在線程中執行api命令

用法: bgapi <api命令>[ <參數>]

complete

Complete.

Usage: complete add <word>|del [<word>|*]

譯者注:該命令從沒用過,不知道幹啥的,知道的童鞋,可以來更新該文檔。

cond

運算指定的條件,並返回結果。

用法: cond <條件表達式> ? <true val> : <false val>

條件表達式支持的條件有:

== 等於 
< 小於 
> 大於

例子: 如果第一個值大於第二個,則返回true

 cond 5 > 3 ? true : false
 true

撥號方案中的例子:

   <action application="set" data="voicemail_authorized=${cond(${sip_authorized} == true ? true : false)}"/>

稍複雜的例子:

   <action application="set" data="voicemail_authorized=${cond(${sip_acl_authed_by} == domains ? false : ${cond(${sip_authorized} == true ? true : false)})}"/>

domain_exists

檢查指定的domain是否存在:

 用法: domain_exists <domain>

eval

Eval (noop). 計算字符串,擴展通道變量.

用法: eval [uuid:<uuid> ]<expression>

例子:

 eval ${domain}
 10.15.0.94

 eval Hello, World!
 Hello, World!

 eval uuid:e72aff5c-6838-49a8-98fb-84c90ad840d9 ${channel-state}
 CS_EXECUTE

expand

執行變量擴展API。

 用法: [uuid:<uuid> ]<cmd> <args>

例子:

 expand originate sofia/internal/1001%${domain} 9999

在這個例子中,擴展的變量是${domain}。比如domain的值是192.168.1.1,則擴展後執行的命令爲:

 originate sofia/internal/1001%192.168.1.1 9999

fsctl

發送freeswitch控制消息。

 用法: fsctl [send_sighup |
               hupall |
               pause [inbound|outbound] |
               resume [inbound|outbound] |
               shutdown [cancel|elegant|asap|restart] |
               last_sps |
               sps [num] |
               sync_clock |
               sync_clock_when_idle |
               reclaim_mem |
               max_sessions |
               min_dtmf_duration [num] |
               max_dtmf_duration [num] |
               default_dtmf_duration [num] |
               loglevel [level] |
               verbose_events [on|off]
              ]

hupall

用於掛斷呼向指定號碼的通話。參數爲:

clearing_type dialed_ext <extension number>

舉個例子來說,殺掉正處於活躍狀態、目標號碼是1000的通話,命令爲:

fsctl hupall normal_clearing dialed_ext 1000

sync_clock

FreeSWITCH不信任系統時間。當系統第一次啓動的時候,從系統時間中獲取樣本時間,然後以此爲基準使用單調時鐘(monotonic clock)。你可以使用命令“fsctl sync_clock”將FreeSWITCH與系統時間進行同步。

注:該命令會立即生效,會影響CDR裏面的時間統計。如會導致計費超前或延後,或者記錄的掛斷時間小於撥打時間。舉個例子來說,如果FS的時鐘比系統時間遲一個月,當進行時間同步後,CDR的呼叫記錄裏面就會出現有的呼叫持續時間爲1個月。

命令fsctl sync_clock_when_idle要安全很多,作用和上面一樣,但是要到系統中所有通道都空閒的時候纔開始時間同步。這種方法不會對CDR產生影響。

sync_clock_when_idle

要到系統沒有通話的時候纔開始時間同步

sps

該設置會改變swithch.conf文件中設置的sessions-per-second(每秒併發通話數)屬性限制

last_sps

查詢顯示目前生效的sessions-per-second屬性。

pause

可以使用參數inbound或outbound來暫停創建呼入或呼出通話,如果沒有指定參數的話,則呼入呼出都暫停。resume的用法類似。

min_dtmf_duration

例子:

fsctl min_dtmf_duration 800

譯者注:沒看懂,就不翻譯出來誤導人了! 
This example sets the min_dtmf_duration switch parameter to 100ms. The number is in clock ticks where clockticks / 8 = ms. The min_dtmf_duration specifies the minimum DTMF duration to use on outgoing events. Events shorter than this will be increased in duration to match min_dtmf_duration. You cannot configure a DTMF duration on a profile that is less than this setting. You may increase this value, but cannot set it lower than 400 (the default). This value cannot exceed max_dtmf_duration. This setting can be changed in switch.conf.xml.

It is worth noting that many devices squelch in-band DTMF when sending RFC 2833. Devices that squelch in-band DTMF have a certain reaction time and clamping time which can sometimes reach as high as 40ms, though most can do it in less than 20ms. As the shortness of your DTMF event duration approaches this clamping threshold, the risk of your DTMF being ignored as a squelched event increases. If your call is always IP-IP the entire route, this is likely not a concern. However, when your call is sent to the PSTN, the RFC 2833 must be encoded in the audio stream. This means that other devices down the line (possibly a PBX or IVR you are calling into) might start considering your DTMF event a squelched tone and ignore it entirely. For this reason, it is recommended that you do not send DTMF events shorter than 80ms.

Checking the current value:

fsctl min_dtmf_duration 0

The code recognizes a duration of 0 as a status check. Instead of setting the value to 0, it simply returns the current value.

====max_dtmf_duration====

Example:

fsctl max_dtmf_duration 80000

This example sets the max_dtmf_duration switch parameter to 10,000ms (10 seconds). The number is in clock ticks (CT) where CT / 8 = ms. The max_dtmf_duration caps the playout of a DTMF event at the specified duration. Events exceeding this duration will be truncated to this duration. You cannot configure a duration on a profile that exceeds this setting. This setting can be lowered, but cannot exceed 192000 (the default). This setting cannot be set lower than min_dtmf_duration. This setting can be changed in switch.conf.xml.

Checking the current value:

fsctl max_dtmf_duration 0

The code recognizes a duration of 0 as a status check. Instead of setting the value to 0, it simply returns the current value.

====default_dtmf_duration====

Example:

fsctl default_dtmf_duration 2000

This example sets the default_dtmf_duration switch parameter to 250ms. The number is in clock ticks (CT) where CT / 8 = ms. The default_dtmf_duration specifies the DTMF duration to use on originated DTMF events or on events that are received without a duration specified. This value can be increased or lowered. This value is lower-bounded by min_dtmf_duration and upper-bounded by max_dtmf_duration. This setting can be changed in switch.conf.xml.

Checking the current value:

fsctl default_dtmf_duration 0

The code recognizes a duration of 0 as a status check. Instead of setting the value to 0, it simply returns the current value.

====verbose_events==== Enables verbose events. Verbose events have '''every''' channel variable in '''every''' event for a particular channel. Non-verbose events have only the pre-selected channel variables in the event headers. * This setting can also be set in [[switch.conf.xml]].

global_getvar

獲取全局變量的值。如果沒有提供參數,則返回所有全局變量的值。

用法: global_getvar <varname>

global_setvar

設置全局變量

用法: global_setvar <varname>=<value>

例子:

global_setvar foo=bar

group_call

返回組呼bridge字符串,組呼定義請參考[[XML User Directory Guide#Groups|call group]]。

Usage: group_call group@domain[+F][+A][+E]

+F將會以串行呼叫模式返回組成員(以“|”隔開各成員). +A將會以並行呼叫模式返回組成員(以“,”隔開各成員). +E將會議呼叫模式返回組成員(以:_:隔開各成員),關於企業呼叫請參考[[Freeswitch_IVR_Originate#Enterprise_originate|enterprise fashion]].

請注意:如果你需要設置在外呼通道上面設置用戶變量,需要確保你的domain或被撥打組的變量列表裏面沒有設置dial-string和group-dial-string,用設置用戶默認組裏面的dial-string和group-dial-string來替代。這樣的話,group_call將會返回user/101,user/將會設置你的外呼通道變量。

help

顯示所有API命令的幫助信息。

用法: help

host_lookup

針對指定域名做主機查詢(host lookup)。

用法: host_lookup <hostname>

hupall

斷開現存通話。

用法: hupall <cause> [<variable> <value>]

掛斷所有含有變量,並且值爲的通話,掛機原因爲。

例子:

originate {foo=bar}sofia/internal/[email protected],sofia/internal/[email protected] &park

hupall normal_clearing foo bar

in_group

判斷用戶是否在指定的組中

用法: in_group <user>[@<domain>] <group_name>

is_lan_addr

判斷IP是否爲內網地址

用法: is_lan_addr <ip>

load

加載外部模塊

用法: load <mod_name>

md5

返回指定數據的MD5值。

用法: md5 <data>

module_exists

檢查模塊是否存在。

用法: module_exists <module>

msleep

休眠指定毫秒

用法: msleep <休眠的毫秒數>

nat_map

用法: nat_map [status|reinit|republish] | [add|del] <port> [tcp|udp] [sticky] | [mapping] <enable|disable>

  • status - 用於顯示NAT類型、外網IP(the external IP)以及當前映射的端口。
  • reinit - 重新初始化NAT模塊。當你更換路由器或將路由器由NAT切換到UPnP模式的時候,使用該參數。
  • republish - 該參數會讓FreeSWITCH重新(向路由器等)發佈NAT映射信息。 正常情況下,沒有必要使用該參數。
  • mapping - 該參數用於控制是否向NAT設備發送端口映射請求(可使用-nonatmap參數在系統啓動時關閉該功能). 之所以存在該參數,是因爲有可能需要通過NAT獲取公網IP地址,而不需要通過NAT開啓端口。

Note: sticky參數用於將映射信息固化下來,在下次FreeSWITCH重啓後映射仍然生效。

警告: 如果你有多個網卡,並分別配置了使用相同端口的sip profiles。nat_map在映射端口的時候,會被弄昏頭的,不需要將端口映射到哪個sip profile上面,千萬別幹這種挫事!

regex

執行正則表達式匹配。該參數會根據是否提供參數而實現不同的功能,如下:

  • 如果沒提供該參數, ''regex'' 將會執行正常的匹配,返回true或者false。
  • 如果提供該參數,如果匹配成功的話,會返回指定的子串。如果匹配失敗,則返回全部源字符串。

默認的正則表達式分界符是|(管道符)。可以更改爲~或者/,只要在字符串的前面加上'm:'。

Usage: regex <data>|<pattern>[|<subst string>]
       regex m:/<data>/<pattern>[/<subst string>]
       regex m:~<data>~<pattern>[~<subst string>]

例子:

 regex test1234|\d                  <== Returns "true"
 regex m:/test1234/\d               <== Returns "true"
 regex m:~test1234~\d               <== Returns "true"
 regex test|\d                      <== Returns "false"
 regex test1234|(\d+)|$1            <== Returns "1234"
 regex sip:[email protected]|^sip:(.*)|$1 <== Returns "[email protected]"
 regex testingonetwo|(\d+)|$1       <== Returns "testingonetwo" (no match)
 regex m:~30~/^(10|20|40)$/~$1      <== Returns "30" (no match)
 regex m:~30~/^(10|20|40)$/~$1~n    <== Returns "" (no match)
 regex m:~30~/^(10|20|40)$/~$1~b    <== Returns "false" (no match)

版本14727中的邏輯是,如果源字符串匹配匹配到結果,那麼條件爲false,但是這裏仍有一個匹配結果,結果是1001。(這裏的翻譯是照字面翻譯,小夥伴們,你們看懂了沒?) 
Logic in revision 14727 if the source string matches the result then the condition was false however there was a match and it is 1001.

regex 1001|(^\d{4}$)|$1

  • See also [[Regular_Expression]]

reload

重新加載模塊。

用法: reload [-f] <mod_name>

reloadacl

重新加載ACL規則。

用法: reloadacl [reloadxml]

reloadxml

重新加載conf/freeswitch.xml的配置信息到內存中。

用法: reloadxml

show

輸出多種(模塊)狀態報告。

 用法: show <item>
  item類型如下:
  codec
  endpoint
  application
  api
  dialplan
  file
  timer
  calls [count]
  channels [count|like <match string>]
  calls
  detailed_calls
  bridged_calls
  detailed_bridged_calls
  aliases
  complete
  chat
  management
  modules
  nat_map
  say
  interfaces
  interface_types
  tasks
  limits

XML格式輸出: show foo as xml

修改輸出分隔符: show foo as delim |

  • codec - 列出所有編碼
  • endpoint - 列出所有endpoint類型模塊
  • application - 列出所有應用程序
  • api - 列出所有api
  • dialplan - 列出撥號方案涉及的模塊
  • file - 列出所有支持的文件類型
  • timer - 列出計時器timer模塊
  • calls - 列出當前的通話[count]
  • channels - 列出當前的通道 [count|like ] 
    注:關於calls與channels的對比,請參考Channels vs Calls
  • bridged_calls - 和"show calls"相同
  • detailed_calls - 和"show calls"類似,但是顯示字段更多
  • detailed_bridged_calls - 和"show calls"類似,但是顯示字段更多
  • aliases - 列出所有別名(別名幹啥用的,暫時未查到)
  • complete - list command complete tables
  • chat - 列出所有chat模塊,包括api、sms、conf等
  • management - list management?
  • modules - 列出所有模塊
  • nat_map - 列出地址映射表
  • say - 列出有支持語言的say模塊
  • interfaces - 列出所有接口
  • interface_types - 列出所有接口類型
  • tasks - 列出任務
  • registrations - 列出所有註冊用戶

Tips For Showing Calls and Channels

理解show calls/channels真義的最好方式是親自去嘗試。最近(2011.9)又在show命令家族中添加了幾位:

  • show detailed_calls
  • show bridged_calls
  • show detailed_bridged_calls

這三個命令用於取代簡單的"show calls"。 
需要注意的是,"show detailed_calls"取代的是"show distinct_channels"。命令都是相似的,但是返回信息更多。 
同樣需要注意的是,這裏並沒有"show detailed_channels"命令,但是使用"show detailed_calls"會讓你得到相同的結果。該命令能讓你得到“單腿通話”(one-legged calls)或橋接後的通話信息,所以,少年,習慣這條新命令吧!

小貼士2: 有時,你需要獲取某個特定的uuid,可以使用下面的方式。 
假設你設置了通道變量presence_data,那可以使用下面的命令搜索符合條件的通道(即含有foo的通道): show channels like foo

like將會搜索下面的關鍵字段:

  • uuid
  • channel name
  • caller id name
  • caller id number
  • presence_data

注: presence_data 必須在bridgeoriginate期間設置,而不是在通道已經建立完成後才設置。

shutdown

停止FreeSWITCH程序。該命令只在cli中起作用,如果想作爲api進行調用,需要使用fsctl shutdown

警告!在cli中運行shutdown會忽略掉參數,並立即退出!

用法: fsctl shutdown [cancel|elegant|asap|restart|now]

  • cancel - 終止上一次提交的shutdown請求
  • elegant - 等待所有通話都停止後才關閉,允許新發起通話.
  • asap - 等待所有通話都停止後才關閉, 不再允許新通話.
  • restart - 在執行完“shutdown”後立即重啓FreeSWITCH。
  • now - 立即重啓FreeSWITCH。

當使用"elegant", "asap"或者"now"參數後,還可以後跟restart命令,如下:

用法: fsctl shutdown [elegant|asap|now] restart

status

顯示當前FreeSWITCH的運行狀態

 用法: status

 freeswitch@internal> status
 UP 0 years, 0 days, 1 hour, 28 minutes, 4 seconds, 208 milliseconds, 305 microseconds
 FreeSWITCH is ready
 4 session(s) since startup
 0 session(s) 0/30                        <- 每秒創建的最大通話數 .. 來自switch.conf.xml
 1000 session(s) max                      <- 同時並存的最大通話數 .. 來自switch.conf.xml
 min idle cpu 0.00/100.00                 <- 達到拒接電話標準的最小閒置CPU值 .. 來自switch.conf.xml (如果該值被啓動的話).

strftime_tz

根據不同的時區,顯示格式化後的時間。需要查看linux時區標準列表的,請查看/usr/share/zoneinfo/zone.tab。

用法: strftime_tz <timezone> [format_string]

示例: strftime_tz US/Eastern %Y-%m-%d %T

unload

卸載外部模塊

用法: unload [-f] <mod_name>

version

顯示FreeSWITCH的版本號

用法: version [short]

xml_locate

xml_locate root: 返回FreeSWITCH使用的所有XML 
xml_locate <section>: 返回指定<section>的XML

xml_locate directory
xml_locate configuration
xml_locate dialplan
xml_locate phrases

用法: xml_locate [root | <section> | <section> <tag> <tag_attr_name> <tag_attr_val>]

示例: xml_locate directory domain name example.com

xml_wrap

使用xml來包裝API命令

用法: xml_wrap <command> <args>

呼叫管理命令

break

被廢棄,請查看uuid_break命令

create_uuid

創建一個新的UUID,並以字符串的形式返回。

用法: create_uuid

originate

發起一個新的呼叫

Usage: originate <call_url> <exten>|&<application_name>(<app_args>)
[<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]

參數:

  • <call_url> 呼叫目標URL. 
    想多瞭解sofia sip URL語法的童鞋可以參考: [[Sofia|FreeSwitch Endpoint Sofia]]
  • 目標有如下幾類:
    • 進入撥號方案進行路由的目標號碼
    • &<application_name>(<app_args>)
      • "&" 表明後面跟的是應用名稱,不是一個目標號碼
      • (<app_args>) 可選參數 (不是所有應用都需要傳遞參數,比如park)
      • 下面是可以用在'&'後面的應用列表:
        park, bridge, javascript/lua/perl, playback (移除mod_native_file), and many others.
      • 注1: 用單引號傳遞含有空格的參數,如'&lua(test.lua arg1 arg2)'
      • 注2: 在&和application_name之間不能含有空格
  • 默認爲'XML',如果沒有特別指定的話。
  • 默認爲'default',如果沒有特別指定的話。
  • 主叫名稱.
  • 主叫號碼.
  • 超時時長(單位爲秒).

可選參數: 
這些可選參數使用大括號包裹,如:

originate {ignore\_early_media=true}sofia/example/user 8334

參數需要使用逗號隔開,例子如下:

originate {ignore_early_media=true,originate_timeout=2}sofia/example/user 8334

  • group_confirm_key
  • group_confirm_file
  • forked_dial
  • fail_on_single_reject
  • ignore_early_media
  • return_ring_ready
  • originate_retries
  • originate_retry_sleep_ms
  • origination_caller_id_name
  • origination_caller_id_number
  • originate_timeout
  • sip_auto_answer

更多變量,參考下面的地址: 
[[Channel_Variables#Originate_related_variables|Description of originate's related variables]]

例子: 
假設,你想撥打一個本地註冊的sip終端,號碼爲300,然後執行park操作,如下: 
(注:本例中用的sip profile是example,你在實際測試的時候,需要改成你本地電話註冊的sip profile,一般爲internal)

originate sofia/example/300%pbx.internal &park()

又或者,你想將遠程註冊的sip終端連到撥號規則8600上

originate sofia/example/[email protected] 8600

再或者,你想將遠程註冊的sip終端連到另一個遠程終端

originate sofia/example/[email protected] &bridge(sofia/example/[email protected])

還或者, 你甚至可以在接通後執行javascript腳本test.js

originate sofia/example/[email protected] &javascript(test.js)

如果運行的javascript腳本需要傳遞參數,則需要使用單引號括起來。

originate sofia/example/[email protected] '&javascript(test.js myArg1 myArg2)'

在發起呼叫前,設置通道變量

originate {ignore_early_media=true}sofia/mydomain.com/[email protected] 15555551212

在發起呼叫期間,設置通道變量,並傳遞給另一個FS

originate {sip_h_X-varA=111,sip_h_X-varB=222}sofia/mydomain.com/[email protected] 15555551212

注: 你可以設置任何類型的通道變量,即使是自定義變量。如果變量的值含有空格或逗號等符號,使用單引號括起來即可。

originate {my_own_var=my_value}sofia/mydomain.com/[email protected] 15555551212
originate {my_own_var='my value'}sofia/mydomain.com/[email protected] 15555551212

如果你想自造一段回鈴音給被呼叫方聽,try this:

originate {ringback=\'%(2000,4000,440.0,480.0)\'}sofia/example/[email protected] &bridge(sofia/example/[email protected])

如果你想發起呼叫後,通道進入"Ring-Ready"狀態後就立即返回,try this:

originate {return_ring_ready=true}sofia/gateway/someprovider/919246461929 &socket(127.0.0.1:8082 async full)

更多信息請查閱return ring ready

你可以將保持等待音樂設置爲回鈴音,if you want:

originate {ringback=\'/path/to/music.wav\'}sofia/gateway/name/number &bridge(sofia/gateway/name/othernumber)

你可以在後臺發起一個呼叫(異步模式),播放一段60秒的提示消息:

bgapi originate {ignore_early_media=true,originate_timeout=60}sofia/gateway/name/number &playback(message)

你可以指定被呼叫方的UUID,只需要下面幾步:

  • 使用create_uuid創建一個UUID,待用。
  • 使用uuid_kill直接可以在對方未接聽前殺掉該次呼叫。
  • 使用origination_uuid指定uuid之後,被叫方會在整個通話的生命週期中使用該UUID。 * originate {origination_uuid=...}user/[email protected]

下面例子作用:發起一個到外部sip服務器echo conference的呼叫,然後轉接到本地用戶分機上

originate sofia/internal/[email protected] &bridge(user/105@default)

下面例子作用:向'default'以外的context上的分機發起呼叫(FreePBX會用到該特性,如context名字爲context_1,context_2等等)

originate sofia/internal/[email protected] 3001 xml context_3

如果你想對多個分機發起呼叫,可以使用下面的命令:

originate user/1001,user/1002,user/1003 &park()

如果需要在收到early media的時候,將外呼的電話轉入會議中,可以使用下面的兩個命令,作用一樣

originate sofia/example/[email protected] &conference(conf_uuid-TEST_CON)
originate sofia/example/[email protected] conference:conf_uuid-TEST_CON inline

   ( See [[Misc._Dialplan_Tools_InlineDialplan]] for more detail on 'inline' Dialplans )

下面的例子演示如何在A-leg上面使用loopback和inline 
我是例子

pause

停止指定通道的媒體播放

用法: pause <uuid> <on|off>

uuid_answer

應答

用法: uuid_answer <uuid>

  • See Also: [[Misc.Dialplan_Tools_answer]]

uuid_audio

調整信道上面的音量,或直接通過一個媒體bug進行靜音(讀/寫)

用法: uuid_audio <uuid> [start [read|write] [mute|level <level>]|stop]

level的值範圍從-4到4,默認值爲0。

uuid_break

斷開發送至指定信道的媒體流。舉例來說,如果此時正在信道上面播放一個音頻文件,使用uuid_break命令,就會斷開媒體,呼叫會順着撥號方案、腳本等往下執行。

用法: uuid_break <uuid> [all]

如果使用all標記的話,所有信道上面正在排隊等待播放的音頻文件都會被移除,但是如果沒有all標記的話,只有當前正在播放的音頻文件會被斷開。

uuid_bridge

橋接兩條呼叫的腿。

Usage: uuid_bridge <uuid> <other_uuid>

uuid_bridge至少需要有一條腿是被呼通的。

uuid_broadcast

在一個指定UUID的信道上執行任意一個撥號方案程序。如果指定了某錄音文件名,則代表將會在該信道上播放該文件。 執行撥號方案程序的語法規則是“app::args”。

用法: uuid_broadcast <uuid> <path> [aleg|bleg|both]

在選定的腿上執行應用程序,執行完畢後掛斷,並指明掛機原因。

用法: uuid_broadcast <uuid> app[![hangup_cause]]::args [aleg|bleg|both]

具體應用舉例如下:

 uuid_broadcast 336889f2-1868-11de-81a9-3f4acc8e505e sorry.wav both
 uuid_broadcast 336889f2-1868-11de-81a9-3f4acc8e505e say::en\snumber\spronounced\s12345 aleg
 uuid_broadcast 336889f2-1868-11de-81a9-3f4acc8e505e say!::en\snumber\spronounced\s12345 aleg
 uuid_broadcast 336889f2-1868-11de-81a9-3f4acc8e505e say!user_busy::en\snumber\spronounced\s12345 aleg
 uuid_broadcast 336889f2-1868-11de-81a9-3f4acc8e505e playback!user_busy::sorry.wav aleg

uuid_buglist

列出信道上面的媒體bug(media bugs)

用法: uuid_buglist <uuid>

uuid_chat

發送聊天信息

用法: <uuid> <text>

如果和會話(session,由uuid指定)相關的終端有一個receive_event handler,該消息會被髮往終端,並以及時消息的形式顯示出來。

uuid_debug_media

該命令過去爲uuid_debug_audio,但是因爲加入了一些視頻的內容,所以改爲現在的名字。

調試媒體流

用法:

<uuid> <read|write|both|vread|vwrite|vboth> <on|off>

使用“read”、“write”或者“both”(同時調試兩個方向)作爲語音流的方向,以進行調試。 在前面加上“v”,代表視頻流的調試。

Read Format

"R %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n"

where the values are:

* switch_channel_get_name(switch_core_session_get_channel(session)),
* (long) bytes,
* my_host, switch_sockaddr_get_port(rtp_session->local_addr),
* old_host, rtp_session->remote_port,
* tx_host, switch_sockaddr_get_port(rtp_session->from_addr),
* rtp_session->recv_msg.header.pt,
* ntohl(rtp_session->recv_msg.header.ts),
* rtp_session->recv_msg.header.m

Write Format

"W %s b=%4ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n"

where the values are:

* switch_channel_get_name(switch_core_session_get_channel(session)),
* (long) bytes,
* my_host, switch_sockaddr_get_port(rtp_session->local_addr),
* old_host, rtp_session->remote_port,
* tx_host, switch_sockaddr_get_port(rtp_session->from_addr),
* send_msg->header.pt,
* ntohl(send_msg->header.ts),
* send_msg->header.m);

uuid_deflect

通過發送REFER方法,將當前FreeSWITCH上面的某個已經應答的sip呼叫轉移走。

用法: uuid_deflect <uuid> <sip URL>

在命令執行後,uuid_deflect等待遠端的應答,以此判斷轉移是否成功。遠端返回的sip內容(sip fragment)將會作爲uuid_deflect命令的返回結果。如果遠端報告REFER成功,FreeSWITCH將會向那條信道發送bye信令。

舉例如下:

uuid_deflect 0c9520c4-58e7-40c4-b7e3-819d72a98614 sip:[email protected]

返回內容:

Content-Type: api/response
Content-Length: 30

+OK:SIP/2.0 486 Busy Here

uuid_displace

將目標信道上面的語音流替換爲指定的錄音(文件)。

參數:

* uuid = 通話的唯一標識符(通過“show channels"可查看到)
* start|stop = 啓動/停止該操作
* file = 要播放的語音源(wav,shout等等)路徑
* limit = 語音替換(文件)的最大播放時長,秒數
* mux = 該選項將會導致原始的語音流與錄音(文件)進行混音。比如,你在替換語音的時候,仍想與另一端進行會話(即在聽到替換的錄音文件的時候,也能聽到對方的聲音)。

用法:

uuid_displace <uuid> [start|stop] <file> [<limit>] [mux]

舉例如下:

uuid_displace 1a152be6-2359-11dc-8f1e-4d36f239dfb5 start /sounds/test.wav 60
uuid_displace 1a152be6-2359-11dc-8f1e-4d36f239dfb5 stop /sounds/test.wav

uuid_display

更新話機的顯示內容,前提是話機支持該功能。目前有Polycom和Snom等部分Sip話機支持該功能。

用法: <uuid> [<display>]

該命令會導致重新協商語音編碼。SIP->RTP包的大小應該是0.020。如果在SPA系統話機上,設置爲0.030的話,會引起DTMF延遲(DTMF lag)。當話機上的按鍵被按下的時候,我們可以通過fs_cli看到,但是會有4到6秒的延遲。

uuid_dual_transfer

將處於通話中的雙方分別轉移到不同的目的地。

-USAGE: <uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]

uuid_dump

導出指定會話中的所有變量

Usage: uuid_dump <uuid> [format]

導出格式: XML

uuid_early_ok

停止忽略早期媒體(即正常播放early media)。 如果此時ignore_early_media=true,該命令將會停止忽略早期媒體(讓參數ignore_early_media設置不起作用),並正常播放。

用法: uuid_early_ok

uuid_exists

檢查給定的uuid是否存在。

用法: uuid_exists

uuid_flush_dtmf

刷新DTMF數字緩存,將在排隊的DTMF全部送出

Usage: uuid_flush_dtmf

uuid_fileman

管理正在信道中播放的音頻流,該音頻來自一個語音文件。

用法: uuid_fileman <cmd:val>

命令如下:

*speed:<+[step]>|<-[step]>    語速
*volume:<+[step]>|<-[step]>   音量
*pause                         暫停
*stop                          停止
*truncate                      截斷
*restart                      重啓
*seek:<+[samples]>|<-[samples]> 定位

Samples,從字面上來講,就是語音文件前進後退的取樣數。在8KHZ的文件中,取樣數8000代表的是一秒。同樣,在16KHZ的文件中,16000代表的也是一秒。

uuid_getvar

獲取指定的信道變量

用法: uuid_getvar

uuid_hold

保持通話

用法:

uuid_hold <uuid>           保持通話
uuid_hold off <uuid>       結束保持,恢復正常通話
uuid_hold toggle <uuid>    在保持和取消保持間切換

uuid_kill

重置(殺掉)指定的信道

用法: uuid_kill [cause]

uuid_limit

Apply or change limit(s) on a specified uuid.

Usage: uuid_limit [[/interval]] [number [dialplan [context]]]

See also [[Limit]]

uuid_media

Reinvite FreeSWITCH out of the media path:

Usage: uuid_media [off]

Reinvite FreeSWITCH back in:

Usage: uuid_media

uuid_media_reneg

API command to tell a channel to send a re-invite with optional list of new codecs

Usage: uuid_media_reneg

uuid_park

Park call

Usage: uuid_park

uuid_preanswer

Preanswer a channel.

Usage: uuid_preanswer

  • See Also: [[Misc._Dialplan_Tools_pre_answer]]

uuid_preprocess

Pre-process Channel

Usage: uuid_preprocess <>

uuid_recv_dtmf

Send DTMF digits to set.

Usage: uuid_recv_dtmf  [@]

Use the character w for a .5 second delay and the character W for a 1 second delay.

Default tone duration is 2000ms .

uuid_send_dtmf

Send DTMF digits.

Usage: uuid_send_dtmf  [@]

Use the character w for a .5 second delay and the character W for a 1 second delay.

Default tone duration is 2000ms .

uuid_send_info

Send info to the endpoint

Usage: uuid_send_info

uuid_session_heartbeat

Usage: uuid_session_heartbeat [sched] [0|]

uuid_setvar

Set a variable on a channel. If value is omitted, the variable is unset.

Usage: uuid_setvar [value]

uuid_setvar_multi

Set multiple vars on a channel.

Usage: uuid_setvar_multi =[;=[;...]]

uuid_simplify

This command directs FreeSWITCH to remove itself from the SIP signaling path if it can safely do so

Usage:

uuid_simplify

uuid_transfer

Transfers an existing call to a specific extension within a and . Dialplan may be "xml" or "directory".

Usage:

uuid_transfer [-bleg|-both] [] []

The optional first argument will allow you to transfer both parties (-both) or only the party to whom is talking.(-bleg)

NOTE: if the call has been bridged, and you want to transfer either sides of the call, then you will need to use (or the API equivalent). If it's not set, transfer doesn't really work as you'd expect, and leaves calls in limbo.

Record/Playback Commands

uuid_record

Record the audio associated with the given UUID into a file. The start command causes FreeSWITCH to start mixing all call legs together and saves the result as a file in the format that the file's extension dictates. (if available) The stop command will stop the recording and close the file. If media setup hasn't yet happened, the file will contain silent audio until media is available. Audio will be recorded for calls that are parked. The recording will continue through the bridged call. If the call is set to return to park after the bridge, the bug will remain on the call, but no audio is recorded until the call is bridged again. (TODO: What if media doesn't flow through FreeSWITCH? Will it re-INVITE first? Or do we just not get the audio in that case?)

Usage:

uuid_record [start|stop]  [ ]

Where limit is the max number of seconds to record.

If the path is not specified on start it will default to the channel variable "sound_prefix" or FreeSWITCH base_dir when the "sound_prefix" is empty.

You may also specify "all" for path when stop is used to remove all for this uuid

"stop" command must be followed by  option.

[[Channel_Variables#Call_Recording_Related|See record's related variables]]

Limit Commands

[[Limit#API|limit_reset]]

Reset a limit backend.

[[Limit#API|limit_status]]

Retrieve status from a limit backend.

[[Limit#API|limit_usage]]

Retrieve usage for a given resource.

[[Limit#API|uuid_limit_release]]

Manually decrease a resource usage by one.

[[Limit#API|limit_interval_reset]]

Reset the interval counter to zero prior to the start of the next interval.

Misc. Commands

bg_system

Execute a system command in the background.

Usage: bg_system

echo

Echo input back to the console echo This text will appear This text will appear

file_exists

Tests whether ''filename'' exists.

file_exists filename

Examples:

file_exists /tmp/real_file true file_exists /tmp/missing_file false

Example dialplan usage:

 <extension name="play-news-announcements">
   <condition expression="${file_exists(${sounds_dir}/news.wav)}" expression="true"/>
     <action application="playback" data="${sounds_dir}/news.wav"/>
     <anti-action application="playback" data="${soufnds_dir}/no-news-is-good-news.wav"/>
   </condition>
 </extension>

'''Note''' this tests whether FreeSWITCH can see the file, but the file may still be unreadable (permissions).

find_user_xml

Checks to see if a user exists; Matches user tags found in the directory, similar to [[user_exists]], but returns an XML representation of the user as defined in the directory (like the one shown in [[Mod_commands#user_exists|user_exists]]).

Usage: find_user_xml

Where key references a key specified in a directory's user tag, user represents the value of the key, and the domain is the domain the user is assigned to.

list_users

Lists Users configured in Directory

Usage: list_users [group ] [domain ] [user ] [context ]

Example:

freeswitch@localhost> list_users group default

userid|context|domain|group|contact|callgroup|effective_caller_id_name|effective_caller_id_number
2000|default|192.168.20.73|default|sofia/internal/sip:[email protected]:5060|techsupport|B#-Test 2000|2000
2001|default|192.168.20.73|default|sofia/internal/sip:[email protected]:63412;rinstance=8e2c8b86809acf2a|techsupport|Test 2001|2001
2002|default|192.168.20.73|default|error/user_not_registered|techsupport|Test 2002|2002
2003|default|192.168.20.73|default|sofia/internal/sip:[email protected]:5060|techsupport|Test 2003|2003
2004|default|192.168.20.73|default|error/user_not_registered|techsupport|Test 2004|2004

+OK

Search items can be combined:

freeswitch@localhost> list_users group default user 2004

userid|context|domain|group|contact|callgroup|effective_caller_id_name|effective_caller_id_number
2004|default|192.168.20.73|default|error/user_not_registered|techsupport|Test 2004|2004

+OK

sched_api

Schedule an API call in the future. Usage: sched_api [+@]

time is the UNIX timestamp at which the command should be executed. If it is prefixed by +, specifies the number of seconds to wait before executing the command. If prefixed by @, it will execute the command periodically everyseconds; for the first time it will be executed after seconds.
group_name will be the value of "Task-Group" in generated events. "none" is the proper value for no group.
command_string is the command executed

Scheduled task or group of tasks can be revoked with sched_del or unsched_api.

You could put "&" symbol at the end of the line to make command to be executed in its own thread.

Example: sched_api +1800 none originate sofia/internal/1000%${sip_profile} &echo() sched_api @600 check_sched log Periodic task is running...

sched_broadcast

Play a  file to a specific call in the future. Usage: sched_broadcast [+]  [aleg|bleg|both]

Schedule execution of an application on a chosen leg(s) with optional hangup: Usage: sched_broadcast [+] app[![hangup_cause]]::args [aleg|bleg|both]

time is the UNIX timestamp at which the command should be executed (or if it is prefixed by +, the number of seconds to wait before executing the command)

Example: sched_broadcast +60 336889f2-1868-11de-81a9-3f4acc8e505e commercial.wav both sched_broadcast +60 336889f2-1868-11de-81a9-3f4acc8e505e say::en\snumber\spronounced\s12345 aleg

sched_del

Removes a prior scheduled group or task ID Usage: sched_del <group_name|task_id>

The one argument can either be a group of prior scheduled tasks or the returned task-id from sched_api.

Example: sched_del my_group sched_del 2

sched_hangup

Schedule a running call to hangup.

Usage: sched_hangup [+] []

Note: sched_hangup +0 is the same as uuid_kill

sched_transfer

Schedule a transfer for a running call.

Usage: sched_transfer [+] [] []

stun

Executes a STUN lookup. Usage: stun [:port]

Example: stun stun.freeswitch.org

system

Execute a system command.

Usage: system

The command is passed to the system shell, where it may be expanded or interpreted in ways you don't expect. This can lead to security bugs if you're not careful. For example, the following command is dangerous:

If a malicious remote caller somehow sets their caller ID name to "; rm -rf /", you would unintentionally be executing this shell command:

log_caller_name; rm -rf /

time_test

Time test.

Usage: time_test [count]

Runs a test to see how bad timer jitter is. It runs the test count times (default 10) and tries to sleep for mss microseconds. It returns the actual timer duration along with an average.

Sample:

time_test 100 5

test 1 sleep 100 99
test 2 sleep 100 97
test 3 sleep 100 96
test 4 sleep 100 97
test 5 sleep 100 102
avg 98

timer_test

Timer test.

Usage: timer_test <10|20|40|60|120> [<1..200>] []

Runs a test to see how bad timer jitter is. Unlike time_test, this uses the actual freeswitch timer infrastructure to do the timer test and exercises the timers used for call processing.

First argument is the timer interval. Second is the count. Third is the timer name ("show timers" will give you a list)

Example:

timer_test 20 3

Avg: 16.408ms Total Time: 49.269ms

2010-01-29 12:01:15.504280 [CONSOLE] mod_commands.c:310 Timer Test: 1 sleep 20 9254
2010-01-29 12:01:15.524351 [CONSOLE] mod_commands.c:310 Timer Test: 2 sleep 20 20042
2010-01-29 12:01:15.544336 [CONSOLE] mod_commands.c:310 Timer Test: 3 sleep 20 19928

tone_detect

Start Tone Detection on a channel.

Usage: tone_detect [ ]

unsched_api

Unschedule an api command.

Usage: unsched_api

url_decode

Usage: url_decode

Url decode a string.

url_encode

Url encode a string.

Usage: url_encode

user_data

Retrieves user information (parameters or variables) as defined in the directory.

Usage: user_data @ [attr|var|param]

Where user is the user's id, domain is the user's domain, var|param specifies whether the info we're requesting is a variable/parameter, and the name is the name (key) of the variable.

Example:

user_data [email protected] param password

will return a result of 1234, and

user_data [email protected] var accountcode

will return a result of 1000 from the example user shown in [[Mod_commands#user_exists|user_exists]], and

user_data [email protected] attr id

will return the user's actual alphanumeric ID (i.e. "john") when number-alias="1000" was set as an attribute for that user.

user_exists

Checks to see if a user exists; Matches user tags found in the directory and returns either true/false:

Usage: user_exists

Where key references a key specified in a directory's user tag, user represents the value of the key, and the domain is the domain the user is assigned to.

Example:

user_exists id 1000 192.168.1.101

will return true where there exists in the directory a user with a key called id whose value equals 1000:  In the above example, we also could have tested for randomvar:

user_exists randomvar 45 192.168.1.101

And we would have received the same results, but:

user_exists accountcode 1000 192.168.1.101

or,

user_exists password 1000 192.168.1.101

Would have returned false.

See Also

  • [[Channel_Variables|Channel Variables]]

[[Category:Integration]] [[Category:Configuration]] [[Category:API]] [[Category:Modules]]

FreeSWITCH核心命令相關文章

怎樣獲取linux核心命令工具的源碼(超級有用)

12/27 07:13

如果想進一步瞭解linux系統,熟悉一些系統底層的東西還是非常必要的,我們可以先了解一些linux命令是如何實現相關功能的,那麼如何獲得命令的源代碼呢?下面我們詳細介紹一下. 下面以獲取cat命令的源代碼爲例說明: rpm -qif `which cat` 將顯示如下信息: --------------------

------------------------------------------------------ Name : coreutils Relocations: (not re

FreeSWITCH 與 Asterisk&lpar;譯&rpar;

02/19 18:44

FreeSWITCH vs Asterisk FreeSWITCH 與 Asterisk 比較 Anthony Minssale/文 Seven/譯 VoIP通信,與傳統的電話技術相比,不僅僅在於絕對的資費優勢,更重要的是很容易地通過開發相應的軟件,使其與企業的業務邏輯緊密集成.Asterisk作爲開源VoIP軟件的代表,以其強大的功能及相對低廉的建設成本,受到了全世界開發者的青睞.而FreeSWITCH作爲VoIP領域的新秀,在性能.穩定性及可伸縮性等方面則更勝一籌.本文原文在http://w

百問freeswitch

01/02 22:34

您還未登錄!|登錄|註冊|幫助 首頁 業界 移動 雲計算 研發 論壇 博客 下載 更多 目錄視圖 摘要視圖 訂閱 投票贏好禮,週週有驚喜! 2014年4月微軟MVP申請開始了! 消滅0回答,贏下載分 "我的2013"年度徵文活動火爆進行中! 專訪Kinect手語翻譯系統團隊 百問FreeSwitch 分類: FreeSwitch 2013-03-08 00:55 458人閱讀 評論(0) 收藏 舉報 VOIP 行業資訊及發展資訊請參考:www.voip123.cn VOIP123聲明:

《FreeSWITCH&colon; VoIP實戰》:FreeSWITCH 架構

12/12 02:42

總體結構 FreeSWITCH 由一個穩定的核心及外圍模塊組成. FreeSWITCH 使用線程模型來處理併發請求,每個連接都在單獨的線程中進行處理.這不僅能提供最大強度的併發,更重要的是,即使某路電話發生問題,也隻影響到它所在的線 程,而不會影響到其它電話.FreeSWITCH 的核心非常短小精悍,這也是保持穩定的關鍵.所有其它功能都在外圍的模塊中.模塊是可以動態加載(以及卸載)的,在實際應用中可以只加載用到的模塊.外圍 模塊通過核心提供的 Public API 與核心進行通信,而核心則通過回

Windows中Netsh命令的典型應用

11/18 01:12

netsh命令已經推出很長時間,在Windows 2000/XP/2003中均帶有Netsh命令.Windows Server 2008只是對netsh的參數項做了些擴展.日常工作中,很多管理員對netsh瞭解不多,甚至不知道在Windows Server 2008中netsh增強了哪些功能.通過閱讀本文,Windows管理員可以找到上面所列問題的答案. 一.什麼是 Netsh? 微軟Windows的netsh是一個命令行腳本實用工具.使用netsh工具 ,可以查看或更改本地計算機或遠程計算機的

深入淺出Docker(二):Docker命令行探祕

12/28 07:46

1. Docker命令行 Docker官方爲了讓用戶快速瞭解Docker,提供了一個交互式教程,旨在幫助用戶掌握Docker命令行的使用方法.但是由於Docker技術的快速發展,此交互式教程已經無法滿足Docker用戶的實際使用需求,所以讓我們一起開始一次真正的命令行學習之旅.首先,Docker的命令清單可以通過運行docker ,或者 docker help 命令得到: $ sudo docker 在Docker容器技術不斷演化的過程中,Docker的子命令已經達到34個之多,其中核心子命令(

AIX 常用命令彙總

12/19 22:10

文檔選項 將此頁作爲電子郵件發送 拓展 Tomcat 應用 下載 IBM 開源 J2EE 應用服務器 WAS CE 新版本 V1.1 級別: 中級 Shiv Dutta, 技術顧問, IBM 2003 年 5 月 06 日2006 年 12 月 07 日 更新 在使用 AIX® 和 System p™ 服務器遇到問題時,您是否希望能夠自己找到答案呢?您是否希望不必總是求助於專業支持人員,從而節省一些時間呢?好,本文的作者將討論一些能夠回答這些問題的 AIX 命令,並告訴您如何進一步尋找其他問題的

《FreeSWITCH&colon; VoIP實戰》: 運行 FreeSWITCH

12/11 06:34

命令行參數 一般來說,FreeSWITCH 不需要任何命令行參數就可以啓動,但在某些情況下,你需要以一些特殊的參數啓動.在此,僅作簡單介紹.如果你知道是什麼意思,那麼你就可以使用,如果不知道,多半你用不到. 使用 freeswitch -help 或 freeswitch --help 會顯示以下信息: -nf                    -- no forking -u [user]              -- 啓動後以非 root 用戶 user 身份運行 -g [group]

linux 常用命令及技巧

06/28 11:19

linux 常用命令及技巧   一. 通用命令: 1. date :print or set the system date and time 2. stty -a: 可以查看或者打印控制字符(Ctrl-C, Ctrl-D, Ctrl-Z等) 3. passwd: print or set the system date and time (用passwd -h查看) 4. logout, login: 登錄shell的登錄和註銷命令 5. pwd: print or set the syste 

 

 

 

發佈了7 篇原創文章 · 獲贊 12 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章