mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE][EXPERIMENTAL] onOpen реализован
This commit is contained in:
parent
1cc08204e5
commit
323cfe763a
3 changed files with 12 additions and 7 deletions
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -23,11 +23,6 @@ public class WebSocketClientHandler extends SimpleChannelInboundHandler<Object>
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue