Showing
1 changed file
with
5 additions
and
6 deletions
@@ -297,7 +297,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -297,7 +297,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
297 | 297 | ||
298 | if (DataConstants.PROVISION.equals(accessToken) || DataConstants.PROVISION.equals(accessToken)) { | 298 | if (DataConstants.PROVISION.equals(accessToken) || DataConstants.PROVISION.equals(accessToken)) { |
299 | deviceSessionCtx.setProvisionOnly(true); | 299 | deviceSessionCtx.setProvisionOnly(true); |
300 | - ctx.writeAndFlush(createTcpConnAckMsg(CONNECTION_ACCEPTED.name())); | 300 | + pushDeviceMsg(ctx,CONNECTION_ACCEPTED.name()); |
301 | } else { | 301 | } else { |
302 | TkScriptInvokeService.authScripts.forEach(id -> { | 302 | TkScriptInvokeService.authScripts.forEach(id -> { |
303 | ListenableFuture item = context.getJsEngine().invokeFunction(id, accessToken); | 303 | ListenableFuture item = context.getJsEngine().invokeFunction(id, accessToken); |
@@ -347,9 +347,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -347,9 +347,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
347 | } | 347 | } |
348 | 348 | ||
349 | 349 | ||
350 | - private ByteBuf createTcpConnAckMsg(String msg) { | ||
351 | - return Unpooled.copiedBuffer(ByteUtils.getBytes(msg, ByteUtils.UTF_8)); | ||
352 | - } | 350 | + |
353 | 351 | ||
354 | @Override | 352 | @Override |
355 | public void channelReadComplete(ChannelHandlerContext ctx) { | 353 | public void channelReadComplete(ChannelHandlerContext ctx) { |
@@ -450,7 +448,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -450,7 +448,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
450 | public void onSuccess(Void msg) { | 448 | public void onSuccess(Void msg) { |
451 | SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), TcpTransportHandler.this); | 449 | SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), TcpTransportHandler.this); |
452 | checkGatewaySession(sessionMetaData); | 450 | checkGatewaySession(sessionMetaData); |
453 | - ctx.writeAndFlush(createTcpConnAckMsg(authEntry.getSuccess())); | 451 | + pushDeviceMsg(ctx,authEntry.getSuccess()); |
454 | deviceSessionCtx.setConnected(true); | 452 | deviceSessionCtx.setConnected(true); |
455 | log.debug("[{}] Client connected!", sessionId); | 453 | log.debug("[{}] Client connected!", sessionId); |
456 | 454 | ||
@@ -474,7 +472,8 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -474,7 +472,8 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
474 | private void onValidateFailed(ChannelHandlerContext ctx, MqttConnectReturnCode msg) { | 472 | private void onValidateFailed(ChannelHandlerContext ctx, MqttConnectReturnCode msg) { |
475 | authedCounter.incrementAndGet(); | 473 | authedCounter.incrementAndGet(); |
476 | if (TkScriptInvokeService.authScripts.size() == authedCounter.intValue()) { | 474 | if (TkScriptInvokeService.authScripts.size() == authedCounter.intValue()) { |
477 | - ctx.writeAndFlush(createTcpConnAckMsg(msg.name())); | 475 | + pushDeviceMsg(ctx,msg.name()); |
476 | + | ||
478 | ctx.close(); | 477 | ctx.close(); |
479 | } | 478 | } |
480 | } | 479 | } |