|
|
|
|
@ -26,9 +26,6 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(WsChannelInboundHandler.class); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private SessionManager sessionManager; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 用于记录和管理所有客户端的channle |
|
|
|
|
*/ |
|
|
|
|
@ -50,18 +47,17 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 每分钟的0s, 打印当前推流通道
|
|
|
|
|
LocalTime localTime = LocalTime.now(); |
|
|
|
|
if (localTime.getSecond() == 0) { |
|
|
|
|
log.warn(BusinessConstant.LOGGER_PREFIX + " : jt1078推送信息 : currentChannel = {}:{}:{}, content = {}", |
|
|
|
|
currentChannel.id(), currentChannel.localAddress(), currentChannel.remoteAddress(), content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
content = content.replace("jtt1078:", ""); |
|
|
|
|
|
|
|
|
|
String curPush = BusinessCacheUtil.getCurrentPushDevice(); |
|
|
|
|
int curPushChannel = BusinessCacheUtil.getCurrentPushChannel(); |
|
|
|
|
|
|
|
|
|
// 每分钟的0s, 打印当前推流通道
|
|
|
|
|
LocalTime localTime = LocalTime.now(); |
|
|
|
|
if (localTime.getSecond() == 0) { |
|
|
|
|
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : jt808当前推流设备 = {}-{}: 1078推流设备信息 = {} ", curPush, curPushChannel, content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (content.contains("-")) { |
|
|
|
|
// 由于1078传过来的信息为(0+clientId+'-'+channelNo), 故此处需要解析
|
|
|
|
|
// 接收jt1078通过websocket传输的数据
|
|
|
|
|
@ -71,38 +67,35 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
BusinessCacheUtil.set1078PushDevice(clientId); |
|
|
|
|
|
|
|
|
|
// 重置1078推送为空的次数
|
|
|
|
|
// BusinessCacheUtil.setPushEmptyTimes(0);
|
|
|
|
|
log.debug(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 1078推流设备 = {} - {} ", clientId, channelNo); |
|
|
|
|
BusinessCacheUtil.setPushEmptyTimes(0); |
|
|
|
|
|
|
|
|
|
// 如果1078推送的正在推流的设备 != 808记录的当前推流的设备, 调用接口通知慢直播服务, 当前推流车辆及推流状态信息
|
|
|
|
|
if (!clientId.equals(curPush)) { |
|
|
|
|
if (SendCommandUtil.getService() != null) { |
|
|
|
|
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 原推流设备 = {} - {} : 更新为1078正在推流设备 = {} - {} ", curPush, curPushChannel, clientId, channelNo); |
|
|
|
|
SendCommandUtil.getService().noticeCarStatus(clientId, Integer.parseInt(channelNo), BusinessConstant.LIVE_STATUS_ONLINE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 若接收到1078推送的当前推流设备为空, 更新808的缓存
|
|
|
|
|
// 若808记录的当前推流设备不为空, 更新808的缓存
|
|
|
|
|
if (!StringUtil.isNullOrEmpty(curPush)) { |
|
|
|
|
if (SendCommandUtil.getService() != null) { |
|
|
|
|
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 原推流设备 = {} - {} : 更新为1078正在推流设备 = null ", curPush, curPushChannel); |
|
|
|
|
SendCommandUtil.getService().noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 若接收到1078推送的当前推流设备为空, 触发自动推流方法
|
|
|
|
|
// int emptyTimes = BusinessCacheUtil.getPushEmptyTimes();
|
|
|
|
|
// // 若持续30s收到的消息都为空, 调用推流方法
|
|
|
|
|
// if (emptyTimes == 30) {
|
|
|
|
|
int emptyTimes = BusinessCacheUtil.getPushEmptyTimes(); |
|
|
|
|
// 若持续30s收到的消息都为空, 调用推流方法
|
|
|
|
|
if (emptyTimes == 30) { |
|
|
|
|
// log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 持续30s收到的消息都为空, 调用推流方法 ");
|
|
|
|
|
if (SendCommandUtil.getService() != null && sessionManager != null && sessionManager.all() != null && sessionManager.all().size() > 0) { |
|
|
|
|
SendCommandUtil.getService().sendToDevice(null, null); |
|
|
|
|
if (SendCommandUtil.getService() != null) { |
|
|
|
|
SendCommandUtil.getService().sendToDevice(null, null); |
|
|
|
|
} |
|
|
|
|
emptyTimes = 0; |
|
|
|
|
} else { |
|
|
|
|
emptyTimes++; |
|
|
|
|
} |
|
|
|
|
// emptyTimes = 0;
|
|
|
|
|
// } else {
|
|
|
|
|
// emptyTimes++;
|
|
|
|
|
// }
|
|
|
|
|
// BusinessCacheUtil.setPushEmptyTimes(emptyTimes);
|
|
|
|
|
BusinessCacheUtil.setPushEmptyTimes(emptyTimes); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
currentChannel.writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " : " + content)); |
|
|
|
|
@ -119,13 +112,8 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb |
|
|
|
|
if (!users.contains(nettyChannel)) { |
|
|
|
|
users.add(nettyChannel); |
|
|
|
|
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket连接 : 客户端上线 : channelId = {} ", nettyChannel.id().asLongText()); |
|
|
|
|
|
|
|
|
|
BusinessCacheUtil.set1078PushDevice(""); |
|
|
|
|
if (SendCommandUtil.getService() != null) { |
|
|
|
|
// 1078上线后, 停止原推流线程, 重新启动线程发送推流命令
|
|
|
|
|
SendCommandUtil.getService().restartSendToDevice(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
BusinessCacheUtil.set1078PushDevice(""); |
|
|
|
|
|
|
|
|
|
ctx.channel().writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " qw12312")); |
|
|
|
|
} |
|
|
|
|
|