Skip to Content
《Asterisk:权威指南》第 5 版
book

《Asterisk:权威指南》第 5 版

by Jim Van Meggelen, Russell Bryant, Leif Madsen
May 2025
Intermediate to advanced
414 pages
5h 2m
Chinese
O'Reilly Media, Inc.
Content preview from 《Asterisk:权威指南》第 5 版

第 13 章 设备状态 设备状态

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

从杂乱中找到简单。

阿尔伯特-爱因斯坦

能够确定连接到电话系统上的设备的状态通常是 有用的。例如,前台接待员可能需要查看办公室内每个人的状态,以确定是否有人可以接听电话。Asterisk 本身也需要这些信息。再比如,如果你要建立一个呼叫队列,正如第 12 章所讨论的,Asterisk 需要知道何时有座席可以接听电话。本章将讨论 Asterisk 中的设备状态概念,以及设备和应用程序如何使用和访问这些信息。

设备状态

Asterisk 提供状态信息的设备有两类 :信道设备(如 PJSIP 端点)和虚拟设备(人们可能希望监控的内置服务,如会议室)。

要引用通道的状态,方法与使用 Dial(),例如DEVICE_STATE(PJSIP/000f300B0B02) ,而引用虚拟设备状态的格式为 virtual device type:identifier例如DEVICE_STATE(ConfBridge:1234)

虚拟设备包括 Asterisk 内部但能提供有用状态信息的设备(见表 13-1)。

表 13-1. Asterisk 可以提供状态信息的设备
设备说明
PJSIP/channel name许多信道的状态都可以被监控,但 PJSIP 信道提供的有用数据量最大;因此,监控 SIP 设备是DEVICE_STATE 最常见的用途。
ConfBridge:conference bridgeMeetMe 会议网桥的状态。该状态将反映会议网桥当前是否有与会者呼叫。有关使用MeetMe() 进行电话会议的更多信息,请参阅第 11 章
Custom:custom name自定义设备状态。这些状态具有自定义名称,可使用DEVICE_STATE() 功能修改。使用示例请参阅"使用自定义设备状态"。
Park:exten@context呼叫停机位的状态。状态信息将反映呼叫者当前是否停在该分机上。有关 Asterisk 中呼叫停放的更多信息,请参阅"呼叫停放"。
Calendar:calendar name日历状态。Asterisk 会使用已命名日历的内容将状态设置为availablebusy

检查设备状态

拨号计划 DEVICE_STATE()dialplan 函数 读取设备的当前状态。

exten => 7012,1,Answer()
 same => n,Set(DeviceIdent=PJSIP/000f300B0B02)
 same => n,Verbose(3,${DeviceIdent} is ${DEVICE_STATE($DeviceIdent})})
 same => n,Hangup()

如果我们从正在检查状态的同一台设备上呼叫分机 7012,Asterisk 控制台上会出现以下冗长信息:

    -- PJSIP/000f300B0B02 is INUSE
备注

第 17 章讨论了 Asterisk 管理器接口(AMI)。GetVar 管理器操作可用于在外部程序中检索设备状态值。您可以用它获取普通变量的值,或从拨号计划函数(如DEVICE_STATE() )返回值。

以下是DEVICE_STATE()函数将返回的值列表(当然,这取决于找到了什么):

  • UNKNOWN

  • NOT_INUSE

  • INUSE

  • BUSY

  • INVALID

  • UNAVAILABLE

  • RINGING

  • RINGINUSE

  • ONHOLD

然后,拨号计划就可以利用这些信息做出呼叫流决策(例如,本地信道振铃时,话务员可能会利用这些信息判断话务员电话正在另一条线路上通话,从而拒绝呼叫,使其回到队列中)。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho

Publisher Resources

ISBN: 9798341659568