mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
WebSocketService использование
This commit is contained in:
parent
b42d3d6a08
commit
3daabe584f
2 changed files with 2 additions and 4 deletions
|
@ -23,6 +23,7 @@
|
|||
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||
public static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||
public static Gson gson;
|
||||
public WebSocketService service = new WebSocketService(LaunchServer.server,gson);
|
||||
|
||||
public static LaunchServer server;
|
||||
public static GsonBuilder builder = new GsonBuilder();
|
||||
|
@ -40,9 +41,7 @@ public void channelActive(ChannelHandlerContext ctx) {
|
|||
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
||||
// ping and pong frames already handled
|
||||
if (frame instanceof TextWebSocketFrame) {
|
||||
String request = ((TextWebSocketFrame) frame).text();
|
||||
JsonResponse response = gson.fromJson(request, JsonResponse.class);
|
||||
response.execute(ctx, frame);
|
||||
service.process(ctx, (TextWebSocketFrame) frame);
|
||||
} else {
|
||||
String message = "unsupported frame type: " + frame.getClass().getName();
|
||||
throw new UnsupportedOperationException(message);
|
||||
|
|
|
@ -22,7 +22,6 @@ public String getType() {
|
|||
@Override
|
||||
public void execute(WebSocketService service,ChannelHandlerContext ctx) {
|
||||
LogHelper.info("Echo: %s",echo);
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame(WebSocketFrameHandler.gson.toJson(new Result(echo))));
|
||||
service.sendObject(ctx,new Result(echo));
|
||||
}
|
||||
public class Result
|
||||
|
|
Loading…
Reference in a new issue