With Version 11.1 of Avayas IP Office, there is the new MTCTI-3 API available. It works by exchanging Protobuf objects over a websocket connection.
There is not much docummentation an virtually no sample code about this api and I have problems communicating with this api.
To observe objects, like users, you have to send subscriptions to the API. First step is to send a SubscribeLines, one should receive an answer which should proivde further information about users. With this information it should be possible to subscribe to these users.
I'm using java.net.http.WebSocket for my websocket client. Cennecting to IPO's websocket works afaik. But I'm not getting any responses or events from the IPO.
I would expect that the answer to SunbscribeLines is processed by WSListener.onBinary but I never receive a response.
Question: Has anyone here used this API and/or has any idea why why I do not get any answer from the api? Is there any working code (javascript, python or what ever will also be ok ;-)) using this api out there?
- onOpen and on onPing show that the connection is established.
Code
Connection WS
HttpClient client = HttpClient.newBuilder()
.version(Version.HTTP_1_1)
.sslContext(sc)
.authenticator(new BasicAuthenticator(user, pass))
.build();
WebSocket ws = client.newWebSocketBuilder()
.subprotocols("openapi")
.buildAsync(URI.create(current_url), new WSListener())
.join();
SubscribeLines
SubscribeLines subscribeLines = SubscribeLines.newBuilder()
.setFlags(7)
.build();
Subscribe subscribe = Subscribe.newBuilder()
.setSubscribeId(linesSubId)
.setRequestid(requestId++)
.setLabel("test")
.setTimeout(3600)
.setLines(subscribeLines)
.build();
Message msg = Message.newBuilder()
.setSubscribe(subscribe)
.build();
ByteBuffer buffer = ByteBuffer.wrap(msg.toByteArray());
CompletableFuture<WebSocket> cfws = ws.sendBinary(buffer, true);
System.out.printf("done(%b) exept(%b) cancel(%b) %n",
cfws.isDone(), cfws.isCompletedExceptionally(), cfws.isCancelled());
// Output: done(true) exept(false) cancel(false)
WSListener
To handle data sent from the IPO side we need an implemtation of WebSocket.Listener
private static class WSListener implements WebSocket.Listener {
@Override
public void onOpen(WebSocket webSocket) {
Listener.super.onOpen(webSocket);
System.out.printf("%1$tH:%1$tM:%1$tS.%1$tL onOpen%n", System.currentTimeMillis());
}
@Override
public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
System.out.printf("%2$tH:%2$tM:%2$tS.%2$tL onText %1$s%n", data, System.currentTimeMillis());
return Listener.super.onText(webSocket, data, last);
}
@Override
public CompletionStage<?> onBinary(WebSocket webSocket, ByteBuffer data, boolean last) {
System.out.printf("%1$tH:%1$tM:%1$tS.%1$tL onBinary %1$s :>", System.currentTimeMillis());
while(data.hasRemaining()) {
System.out.printf(" %x", data.get());
}
System.out.printf("<:%n");
return Listener.super.onBinary(webSocket, data, last);
}
@Override
public void onError(WebSocket webSocket, Throwable error) {
// ...
}
@Override
public CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message) {
// ...
}
@Override
public CompletionStage<?> onPong(WebSocket webSocket, ByteBuffer message) {
// ...
}
@Override
public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String reason) {
System.out.printf("%3$tH:%3$tM:%3$tS.%3$tL onClose %1$d %2$s%n", statusCode, reason, System.currentTimeMillis());
return Listener.super.onClose(webSocket, statusCode, reason);
}
}