gpt4 book ai didi

java - 获取/订阅 stasis 消息( Asterisk ARI)

转载 作者:行者123 更新时间:2023-12-02 04:41:08 25 4
gpt4 key购买 nike

我正在尝试将消息从 custum asterisk 插件发送到我的应用程序。

经过一番努力,我可以从我的插件发送停滞消息,但我不知道如何在java中处理它们。 (我使用 ari4java 项目)。

在插件上,我使用两种不同的方法发送消息:

stasis_publish("StasisTest", msg);
// or
int result = stasis_app_send("StasisTest", inte);

我可以在插件中获取消息,所以我想消息已发送到应用程序。

首先是我的extension.conf

exten => 3000,1,NoOp(test ARI)
same => n,Answer()
same => n,StasisTest()

在java方面,我不知道在哪里可以接收消息,我猜想是由AriCallback或AriCallback处理的:

    private static class DummyCallBack implements AriCallback<Message> {

@Override
public void onSuccess(Message result) {
System.out.println(String.format("Dummy message callback receive [%s] with class [%s]",
result.getType(),
result.getClass()));
}

@Override
public void onFailure(RestException e) {
System.out.println("fail callback message");
}
}

private static class AppDummyCallback implements AriCallback<ch.loway.oss.ari4java.generated.Application> {

@Override
public void onSuccess(ch.loway.oss.ari4java.generated.Application result) {
System.out.println(String.format("Dummy Application callback receive name [%s] with class [%s]",
result.getName(),
result.getClass()));
}

@Override
public void onFailure(RestException e) {
System.out.println("fail callback application");
}
}

我注册到 ARI(工作正常):

ari = AriFactory.nettyHttp(url, username, password, AriVersion.ARI_1_7_0);

我尝试获取消息通知:

public static AriApplication createAriApplication(final ARI ari,
final String applicationName,
final EndpointTypes endpointTypes,
final AriCallback<Message> callback,
final AriCallback<Application> appHandler
) throws ARIException {
ActionEvents actionApplications = ari.getActionImpl(ActionEvents.class);
actionApplications.eventWebsocket(applicationName, callback);

ari.applications().subscribe(applicationName, endpointTypes.getEndpoint(), appHandler);
return new AriApplication(ari, applicationName, callback);
}

public AriApplication(final ARI ari,
final String applicationName,
final AriCallback<Message> callback) throws ARIException {
this.ari = ari;

this.applicationName = applicationName;
ActionEvents actionEvents = ari.getActionImpl(ActionEvents.class);
actionEvents.eventWebsocket(applicationName, callback);
}

当我调用 [3000] 电话时,我得到以下输出:

Dummy Application callback receive name [StasisTest] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.Application_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ApplicationReplaced_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.EndpointStateChange_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelCreated_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelStateChange_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelDialplan_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelDialplan_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelStateChange_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelDialplan_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelHangupRequest_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelVarset_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.ChannelDestroyed_impl_ari_1_7_0]
Dummy message callback receive [null] with class [class ch.loway.oss.ari4java.generated.ari_1_7_0.models.EndpointStateChange_impl_ari_1_7_0]

我想这些消息都不是我的消息,我怎样才能取回这条停滞消息?它们会被发送到 ARI 吗?如果没有,我可以在 ARI 和我的插件之间发送什么样的消息?

最佳答案

我用你的例子作为我自己项目的起点,这是我到目前为止所想到的:

private static class DummyCallBack implements AriCallback<Message> {

@Override
public void onSuccess(Message result) {
System.out.println(String.format("Dummy message callback receive [%s] with class [%s]",
result.getType(),
result.getClass()));

if (result instanceof StasisStart)
{
StasisStart stasisStart = (StasisStart)result;
System.out.println
(
String.format("StasisStart - Channel: %s State: %s", stasisStart.getChannel().getId(), stasisStart.getChannel().getState())
);

} else if (result instanceof ChannelDtmfReceived) {

ChannelDtmfReceived channelDtmfReceived = (ChannelDtmfReceived)result;
System.out.println
(
String.format("ChannelDtmfReceived received - Channel: %s Digit: %s", channelDtmfReceived.getChannel().getId(), channelDtmfReceived.getDigit())
);

} else if (result instanceof ChannelHangupRequest) {

ChannelHangupRequest channelHangupRequest = (ChannelHangupRequest)result;

System.out.println
(
String.format("ChannelHangupRequest - Channel: %s", channelHangupRequest.getChannel().getId())
);

} else if (result instanceof StasisEnd) {

StasisEnd stasisEnd = (StasisEnd)result;

System.out.println
(
String.format("Stasis End")
);
}

}

@Override
public void onFailure(RestException e) {
System.out.println("fail callback message");
}
}

关于java - 获取/订阅 stasis 消息( Asterisk ARI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30164554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com