C# Asterisk.NET:当人类拿起手机时,如何钩住事件?
当人类拿起手机时,我会立即添加动作(例如:打开C# Asterisk.NET:当人类拿起手机时,如何钩住事件?,c#,voip,asterisk,C#,Voip,Asterisk,当人类拿起手机时,我会立即添加动作(例如:打开记事本)。我应该使用哪个事件?我从ManagerConnection尝试了很多事件,但找不到解决方案 编辑:我将执行与屏幕截图相同的功能(当人类拿起手机时,制作一些东西)。ADAT程序具有此功能,并且也将具有此功能 编辑2:我找到了解决方案。示例代码: 订阅活动 managerConnection.NewState += new NewStateEventHandler(Monitoring_NewState); private void
记事本)。我应该使用哪个事件
?我从ManagerConnection
尝试了很多事件
,但找不到解决方案
编辑:我将执行与屏幕截图相同的功能(当人类拿起手机时,制作一些东西)。ADAT程序具有此功能,并且也将具有此功能
编辑2:我找到了解决方案。示例代码:
订阅活动
managerConnection.NewState += new NewStateEventHandler(Monitoring_NewState);
private void Monitoring_NewState(object sender, NewStateEvent e)
{
string state = e.State;
string callerID = e.CallerId;
if ((state == "Ringing") | (e.ChannelState == "5"))
{
String connectedLineNum;
String connectedLineName;
Dictionary<String, String> attributes = e.Attributes;
attributes.TryGetValue("connectedlinenum", out connectedLineNum);
attributes.TryGetValue("connectedlinename", out connectedLineName);
// "callerID" - called phone number
// "connectedLineNum" - calling phone number
// CallIn. Incoming call
}
else if ((state == "Ring") | (e.ChannelState == "4"))
{
// CallOut. Outcoming call
}
else if ((state == "Up") | (e.ChannelState == "6"))
{
String connectedLineNum;
String connectedLineName;
Dictionary<String, String> attributes = e.Attributes;
attributes.TryGetValue("connectedlinenum", out connectedLineNum);
attributes.TryGetValue("connectedlinename", out connectedLineName);
// "callerID" - called phone number
// "connectedLineNum" - calling phone number
// human lifted up the phone right now
}
}
managerConnection.NewState+=新的NewStateEventHandler(监视\u NewState);
私有无效监视_NewState(对象发送方,NewState事件)
{
字符串状态=e.状态;
字符串callerID=e.callerID;
如果((状态==“振铃”)|(e.ChannelState==“5”))
{
字符串连接linenum;
字符串connectedLineName;
字典属性=e.属性;
TryGetValue(“connectedlinenum”,out connectedlinenum);
attributes.TryGetValue(“connectedlinename”,out connectedlinename);
//“callerID”-被叫电话号码
//“connectedLineNum”-呼叫电话号码
//呼叫,来电
}
else if((state==“Ring”)|(e.ChannelState==“4”))
{
//呼叫,呼出呼叫
}
如果((state==“Up”)|(e.ChannelState==“6”))
{
字符串连接linenum;
字符串connectedLineName;
字典属性=e.属性;
TryGetValue(“connectedlinenum”,out connectedlinenum);
attributes.TryGetValue(“connectedlinename”,out connectedlinename);
//“callerID”-被叫电话号码
//“connectedLineNum”-呼叫电话号码
//人类现在拿起了电话
}
}
在voip情况下,当人类举起手机时,什么也不会发生。Voip/sip是数字网络,因此,如果不发生任何事情(用户未输入电话号码),则电话(客户端)不是distrub服务器。有些客户机在电梯上自动拨号(用于电话卡公用电话安装),但大多数电话只是不通知服务器(星号)。因此,您无法在程序中获取此事件。您需要澄清:当有人拿起电话时,您是否想要它?还是有人接电话?这是一个巨大的区别。当有人拿起电话时。谢谢,我已经找到了必要的事件,并使用了截图中的.NET Reflector程序进行逆向工程编程:)我很高兴您找到了它-您应该添加一个解释如何执行的答案,以便具有相同问题的其他人可以受益。