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);