use of org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage in project Signal-Android by WhisperSystems.
the class WebSocketConnection method onMessage.
@Override
public synchronized void onMessage(WebSocket webSocket, ByteString payload) {
try {
WebSocketMessage message = WebSocketMessage.parseFrom(payload.toByteArray());
if (message.getType().getNumber() == WebSocketMessage.Type.REQUEST_VALUE) {
incomingRequests.add(message.getRequest());
} else if (message.getType().getNumber() == WebSocketMessage.Type.RESPONSE_VALUE) {
OutgoingRequest listener = outgoingRequests.remove(message.getResponse().getId());
if (listener != null) {
listener.onSuccess(new WebsocketResponse(message.getResponse().getStatus(), new String(message.getResponse().getBody().toByteArray()), message.getResponse().getHeadersList(), !credentialsProvider.isPresent()));
if (message.getResponse().getStatus() >= 400) {
healthMonitor.onMessageError(message.getResponse().getStatus(), credentialsProvider.isPresent());
}
} else if (keepAlives.remove(message.getResponse().getId())) {
healthMonitor.onKeepAliveResponse(message.getResponse().getId(), credentialsProvider.isPresent());
}
}
notifyAll();
} catch (InvalidProtocolBufferException e) {
warn(e);
}
}
use of org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage in project Signal-Android by WhisperSystems.
the class WebSocketConnection method sendRequest.
public synchronized Single<WebsocketResponse> sendRequest(WebSocketRequestMessage request) throws IOException {
if (client == null) {
throw new IOException("No connection!");
}
WebSocketMessage message = WebSocketMessage.newBuilder().setType(WebSocketMessage.Type.REQUEST).setRequest(request).build();
SingleSubject<WebsocketResponse> single = SingleSubject.create();
outgoingRequests.put(request.getId(), new OutgoingRequest(single));
if (!client.send(ByteString.of(message.toByteArray()))) {
throw new IOException("Write failed!");
}
return single.subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).timeout(10, TimeUnit.SECONDS, Schedulers.io());
}
use of org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage in project libsignal-service-java by signalapp.
the class WebSocketConnection method sendRequest.
public synchronized Future<Pair<Integer, String>> sendRequest(WebSocketRequestMessage request) throws IOException {
if (client == null || !connected)
throw new IOException("No connection!");
WebSocketMessage message = WebSocketMessage.newBuilder().setType(WebSocketMessage.Type.REQUEST).setRequest(request).build();
SettableFuture<Pair<Integer, String>> future = new SettableFuture<>();
outgoingRequests.put(request.getId(), future);
if (!client.send(ByteString.of(message.toByteArray()))) {
throw new IOException("Write failed!");
}
return future;
}
use of org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage in project libsignal-service-java by signalapp.
the class WebSocketConnection method onMessage.
@Override
public synchronized void onMessage(WebSocket webSocket, ByteString payload) {
Log.w(TAG, "WSC onMessage()");
try {
WebSocketMessage message = WebSocketMessage.parseFrom(payload.toByteArray());
Log.w(TAG, "Message Type: " + message.getType().getNumber());
if (message.getType().getNumber() == WebSocketMessage.Type.REQUEST_VALUE) {
incomingRequests.add(message.getRequest());
} else if (message.getType().getNumber() == WebSocketMessage.Type.RESPONSE_VALUE) {
SettableFuture<Pair<Integer, String>> listener = outgoingRequests.get(message.getResponse().getId());
if (listener != null)
listener.set(new Pair<>(message.getResponse().getStatus(), new String(message.getResponse().getBody().toByteArray())));
}
notifyAll();
} catch (InvalidProtocolBufferException e) {
Log.w(TAG, e);
}
}
Aggregations