From 323cfe763adc7725ca62755811a472ae1eb233c4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 13:38:35 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20onOpen=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/request/websockets/ClientJSONPoint.java | 1 + .../request/websockets/ClientWebSocketService.java | 8 ++++++++ .../request/websockets/WebSocketClientHandler.java | 10 +++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index 91f1b554..be03e5f4 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -84,6 +84,7 @@ public ChannelFuture send(String text) } abstract void onMessage(String message) throws Exception; abstract void onDisconnect() throws Exception; + abstract void onOpen() throws Exception; public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 2a39a54f..b47ccf66 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -63,6 +63,14 @@ void onDisconnect() { if(onCloseCallback != null) onCloseCallback.onClose(0,"unsupported param", !isClosed); } + @Override + void onOpen() throws Exception { + synchronized (onConnect) + { + onConnect.notifyAll(); + } + } + @FunctionalInterface public interface OnCloseCallback { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java index 41d98c39..da494a72 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -23,11 +23,6 @@ public class WebSocketClientHandler extends SimpleChannelInboundHandler private final WebSocketClientHandshaker handshaker; private final ClientJSONPoint clientJSONPoint; private ChannelPromise handshakeFuture; - interface OnMessageCallback - { - void onMessage(String text); - } - public OnMessageCallback onMessageCallback; public WebSocketClientHandler(final WebSocketClientHandshaker handshaker, ClientJSONPoint clientJSONPoint) { this.handshaker = handshaker; @@ -46,6 +41,7 @@ public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { handshaker.handshake(ctx.channel()); + clientJSONPoint.onOpen(); } @Override @@ -66,7 +62,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except if (msg instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) msg; - throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } @@ -89,7 +85,7 @@ else if (frame instanceof BinaryWebSocketFrame) { @Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { - cause.printStackTrace(); + LogHelper.error(cause); if (!handshakeFuture.isDone()) { handshakeFuture.setFailure(cause);