I would like my ColdFusion app to be able to record events being streamed via telnet from an Asterisk host through the Management API. The ColdFusion Event gateway can listen to a particular port but cannot initiate a connection itself, so I need a gateway that can initiate a telnet connection to the Asterisk host (on a specified port) and push the streamed events to the ColdFusion server (on a specified port). I really don't want to reinvent the wheel so are there any utilities out that that can do this?

我希望我的ColdFusion应用程序能够通过管理API从Asterisk主机记录通过telnet传输的事件。ColdFusion事件网关可以侦听特定的端口,但不能初始化连接本身,因此我需要一个网关,它可以初始化到Asterisk主机(在指定端口上)的telnet连接,并将流事件推到ColdFusion服务器(在指定端口上)。我真的不想重新发明轮子所以有什么工具可以做这个吗?

My terminology may not be correct as I'm not that technical but I hope I've explained the requirement enough! The 'utility' could reside on a Linux or windows platform.

我的术语可能不正确,因为我不是技术,但我希望我已经解释了足够的要求!“实用程序”可以驻留在Linux或windows平台上。

EDIT: To connect to and be authenticated by the Asterisk host telnet stream, the following must be sent:

编辑:要连接并通过星号主机telnet流进行身份验证,必须发送以下命令:

Action: login<CRLF>
Username: usr<CRLF>
Secret: abc123<CRLF>
<CRLF>

I am aware that a previous question was posted similar to this (but not answered), but I'm happy for a solution outside ColdFusion

我知道之前的一个问题与此类似(但没有回答),但我很高兴能在ColdFusion之外找到解决方案

Thanks

谢谢

4 个解决方案

#1


1

If all you need to do is capture events from the Asterisk server, I would suggest a different approach.

如果您需要做的只是从Asterisk服务器捕获事件,那么我建议采用另一种方法。

As you seem to be using the Asterisk AMI, take a look Asterisk-Java. From what I have read, it is a java library that handles the low level socket communication and parsing for you and provides a higher level interface for interacting with an Asterisk server. So it is capable of initiating a connection, capturing events and a lot more.

当您似乎在使用星号AMI时,请查看星号- java。根据我的阅读,它是一个java库,为您处理低级套接字通信和解析,并提供与Asterisk服务器交互的高级接口。所以它可以启动连接,捕获事件等等。

In theory you could open a connection and register to receive events when the application starts. As long as the connection stays open, the application will receive events from Asterisk. When the application ends, just close the connection to halt the events.

理论上,当应用程序启动时,可以打开连接并注册以接收事件。只要连接保持打开,应用程序将接收来自星号的事件。当应用程序结束时,只需关闭连接以停止事件。

Initialize Connection

初始化连接

To simply capture events, start by creating a connection to the Asterisk server. Just supply the proper host and credentials:

要简单地捕获事件,首先创建到Asterisk服务器的连接。只要提供适当的主机和凭证:

managerFactory = createObject("java", "org.asteriskjava.manager.ManagerConnectionFactory");
connection = managerFactory.init( hostNameOrIP
                                 , portNum
                                 , userName
                                 , theSecret ).createManagerConnection();

Registering for Events

注册事件

In order to receive events, you must first register a ManagerEventListener with the connection. Normally that would require writing a custom java class that implements the proper interface. However, with a bit of dynamic proxy magic, you can use a standard CFC instead. Any events from Asterisk will be routed directly to the CFC and can be handled with CF code.

为了接收事件,您必须首先向连接注册ManagerEventListener。通常,这需要编写实现适当接口的自定义java类。但是,使用一些动态代理魔法,您可以使用标准的CFC。任何来自Asterisk的事件都将被直接路由到CFC,可以使用CF代码进行处理。

To add a listener, create a CFC with a single function named onManagerEvent. This function will be called whenever a registered event occurs on the Asterisk server.

要添加侦听器,请使用名为onManagerEvent的单个函数创建CFC。每当在星号服务器上发生注册事件时,就会调用此函数。

// YourCFCListener.cfc
component {
    public void function onManagerEvent(any managerEvent)
    {
        // For demo purposes, just output a summary of the event to a log file
        WriteLog( text=arguments.managerEvent.toString(), file="AsteriskListenerLog" );
    }
}

Next create a proxy and register it with the connection.

接下来创建一个代理并将其注册到连接中。

proxyListener = createDynamicProxy("path.YourCFCListener"
      , [ "org.asteriskjava.manager.ManagerEventListener"] );
connection.addEventListener( proxyListener );

Receiving Events:

接收事件:

To start receiving events, login and connect to the server. Use the mask to specify the events you want to receive: "off", "on" or a comma delimited list of specific events (ie "system,call,log").

要开始接收事件,请登录并连接到服务器。使用掩码指定要接收的事件:“off”、“on”或一个由逗号分隔的特定事件列表(即“system,call,log”)。

// receive ALL events
connection.login("on");

Once the connection is open, you will see events written to the demo log file (assuming there is server activity). For a one time test, let the page sleep() for a few seconds to allow some events to flow. Then close the connection and stop the events:

打开连接后,您将看到编写到演示日志文件的事件(假设有服务器活动)。对于一个时间测试,让页面休眠()几秒钟,以允许一些事件流。然后关闭连接并停止事件:

sleep(4000);
connection.logoff()

In a real application, you would probably open the connection once and store it in a persistent scope, like application. Then close it only when the application shuts down.

在实际的应用程序中,您可能只打开一次连接,并将其存储在一个持久范围内,如应用程序。然后在应用程序关闭时关闭它。

Looking at the API, there is a LOT more you can do with it. However, the above should provide a basic POC example to get you started with capturing events.

看看这个API,你还可以用它做很多事情。但是,上面应该提供一个基本的POC示例,让您开始捕获事件。

更多相关文章

  1. 我如何在Linux和Python中监听“usb设备插入”事件?
  2. 清华大学出版社“抄袭事件”回放
  3. Inotify: 高效、实时的Linux文件系统事件监控框架
  4. mysql创建任务事件
  5. C#的委托事件在winform窗体中实现传值备忘
  6. Android中RecyclerView的item中控件的点击事件添加删除一行、上
  7. android 屏幕触摸事件及处理机制解读
  8. Android事件分发机制(下)
  9. Android 事件输入系统整体框架

随机推荐

  1. android如何调用显示和隐藏系统默认的输
  2. Android的一些小问题处理
  3. Android API 中文 (42) —— ListView
  4. Android开源项目第二篇——工具库篇
  5. android中的TextView滾動條的設置
  6. Android剪裁图片简单的方法
  7. android之HttpPost&HttpGet使用方法介绍
  8. 界面可视化工具------DroidDraw
  9. Android的UI两大基石
  10. Android应用程序获取系统权限