我正在尝试将来自custum asterisk插件的消息发送到我的应用程序。
经过一番努力,我可以从我的插件发送stasis消息,但我不知道如何在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和我的插件之间发送什么样的消息?
答案 0 :(得分:1)
我用你的例子作为我自己项目的起点,这是我到目前为止所提出的:
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");
}
}