use of okhttp3.WebSocket in project Rocket.Chat.Android by RocketChat.
the class RxWebSocket method connect.
public ConnectableFlowable<RxWebSocketCallback.Base> connect(String url) {
final Request request = new Request.Builder().url(url).build();
return Flowable.create((FlowableOnSubscribe<RxWebSocketCallback.Base>) emitter -> httpClient.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
RxWebSocket.this.webSocket = webSocket;
emitter.onNext(new RxWebSocketCallback.Open(RxWebSocket.this.webSocket, response));
}
@Override
public void onFailure(WebSocket webSocket, Throwable err, Response response) {
try {
emitter.onError(new RxWebSocketCallback.Failure(webSocket, err, response));
} catch (OnErrorNotImplementedException ex) {
RCLog.w(ex, "OnErrorNotImplementedException ignored");
}
}
@Override
public void onMessage(WebSocket webSocket, String text) {
emitter.onNext(new RxWebSocketCallback.Message(webSocket, text));
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
emitter.onNext(new RxWebSocketCallback.Close(webSocket, code, reason));
emitter.onComplete();
}
}), BackpressureStrategy.BUFFER).publish();
}
use of okhttp3.WebSocket in project Fast-Android-Networking by amitshekhariitbhu.
the class WebSocketActivity method connectWebSocket.
private void connectWebSocket() {
OkHttpClient client = new OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).build();
Request request = new Request.Builder().url("ws://echo.websocket.org").build();
webSocket = client.newWebSocket(request, getWebSocketListener());
}
use of okhttp3.WebSocket in project okhttp by square.
the class OkHttpClient method newWebSocket.
/**
* Uses {@code request} to connect a new web socket.
*/
@Override
public WebSocket newWebSocket(Request request, WebSocketListener listener) {
RealWebSocket webSocket = new RealWebSocket(request, listener, new SecureRandom());
webSocket.connect(this);
return webSocket;
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method throwingOnFailLogs.
@Ignore("AsyncCall currently lets runtime exceptions propagate.")
@Test
public void throwingOnFailLogs() throws InterruptedException {
TestLogHandler logs = new TestLogHandler();
Logger logger = Logger.getLogger(OkHttpClient.class.getName());
logger.addHandler(logs);
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("Body"));
final RuntimeException e = new RuntimeException();
clientListener.setNextEventDelegate(new WebSocketListener() {
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
throw e;
}
});
newWebSocket();
assertEquals("", logs.take());
logger.removeHandler(logs);
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onClosed.
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onClose " + code, null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onClosed(webSocket, code, reason);
} else {
events.add(new Closed(code, reason));
}
}
Aggregations