|
|
|
|
@ -7,6 +7,7 @@ import io.netty.channel.group.ChannelGroup; |
|
|
|
|
import io.netty.channel.group.DefaultChannelGroup; |
|
|
|
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
|
|
|
|
import io.netty.util.concurrent.GlobalEventExecutor; |
|
|
|
|
import io.netty.util.internal.StringUtil; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.yzh.commons.constant.BusinessConstant; |
|
|
|
|
@ -14,6 +15,7 @@ import org.yzh.commons.util.BusinessCacheUtil; |
|
|
|
|
import org.yzh.web.util.SendCommandUtil; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.LocalTime; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 处理消息的handler |
|
|
|
|
@ -37,6 +39,12 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
// 获取客户端传输过来的消息
|
|
|
|
|
String content = msg.text(); |
|
|
|
|
|
|
|
|
|
// 每分钟的0s, 打印当前推流通道
|
|
|
|
|
LocalTime localTime = LocalTime.now(); |
|
|
|
|
if (localTime.getSecond() == 0) { |
|
|
|
|
log.info(BusinessConstant.LOGGER_PREFIX + " : jt1078推送信息 : content = {}", content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (content.contains("-")) { |
|
|
|
|
// 由于1078传过来的信息为(0+clientId+'-'+channelNo), 故此处需要解析
|
|
|
|
|
// 接收jt1078通过websocket传输的数据
|
|
|
|
|
@ -55,7 +63,17 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
SendCommandUtil.getService().noticeCarStatus(clientId, Integer.parseInt(channelNo), BusinessConstant.LIVE_STATUS_ONLINE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 若接收到1078推送的当前推流设备为空, 更新808的缓存
|
|
|
|
|
String curPush = BusinessCacheUtil.getCurrentPushDevice(); |
|
|
|
|
if (!StringUtil.isNullOrEmpty(curPush)) { |
|
|
|
|
if (SendCommandUtil.getService() != null) { |
|
|
|
|
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 更新为1078正在推流设备 = {} - {} ", curPush, "null"); |
|
|
|
|
SendCommandUtil.getService().noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
currentChannel.writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " : " + content)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -68,7 +86,7 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
public void handlerAdded(ChannelHandlerContext ctx) throws Exception { |
|
|
|
|
users.add(ctx.channel()); |
|
|
|
|
log.info("netty 获得连接..... "); |
|
|
|
|
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket连接 : 客户端上线 : channelId = {} ", ctx.channel().id().asShortText()); |
|
|
|
|
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket连接 : 客户端上线 : channelId = {} ", ctx.channel().id().asShortText()); |
|
|
|
|
|
|
|
|
|
ctx.channel().writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " qw12312")); |
|
|
|
|
|
|
|
|
|
|