Asterisk ARI接口的一個Java綁定:ari4java

jopen 10年前發布 | 25K 次閱讀 ari4java 電話/通訊/IM聊天

ari4java是 Asterisk REST Interface (ARI) 的一個Java綁定。

ARI是 Asterisk 12 提供的一個接口,可以讓你編寫通過REST調用運行在外部和控制呼叫流程的應用,同時接收WebSocket上的事件的應用程序。

為了使用 Netty.io HTTP+WS 實現,需要包含 netty-all-4.0.12.Final.jar或更新的版本在classpath.中

初始化:

    ARI ari = new ARI();
    NettyHttpClient hc = new NettyHttpClient();
    hc.initialize("http://my-pbx-ip:8088/", "admin", "admin");
    ari.setHttpClient(hc);
    ari.setWsClient(hc);
    ari.setVersion(AriVersion.ARI_0_0_1);

簡單的同步調用:

    ActionApplications ac = ari.getActionImpl(ActionApplications.class);
    List<? extends Application> alist = ac.list();

簡單的異步調用:

    ActionAsterisk aa = ari.getActionImpl(ActionAsterisk.class);
    aa.getGlobalVar("AMPMGRPASS", new AriCallback<Variable>() {
        @Override
        public void onSuccess(Variable result) {
            // Let's do something with the returned value
        }
        @Override
        public void onFailure(RestException e) {
            e.printStackTrace();
        }
    });

WebSocket 連接示例,waiting for events on hello and goodbye apps:

    ActionEvents ae = ari.getActionImpl(ActionEvents.class);
    ae.eventWebsocket("hello,goodbye", new AriCallback<Message>() {
        @Override
        public void onSuccess(Message result) {
            // Let's do something with the event
        }
        @Override
        public void onFailure(RestException e) {
            e.printStackTrace();
        }
    });
    Thread.sleep(5000); // Wait 5 seconds for events
    ari.closeAction(ae); // Now close the websocket


 

項目主頁:http://www.baiduhome.net/lib/view/home/1388623340125

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!