|
|
|
|
@ -59,9 +59,7 @@ public class SendCommandService { |
|
|
|
|
* 自动发送推流命令 |
|
|
|
|
*/ |
|
|
|
|
public void sendToDevice() { |
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(null); |
|
|
|
|
BusinessCacheUtil.setPushStatus(BusinessConstant.LIVE_STATUS_WAITING); |
|
|
|
|
noticeCarStatus(); |
|
|
|
|
noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_WAITING); |
|
|
|
|
|
|
|
|
|
Thread thread = new Thread(new Runnable() { |
|
|
|
|
@Override |
|
|
|
|
@ -74,9 +72,7 @@ public class SendCommandService { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(null); |
|
|
|
|
BusinessCacheUtil.setPushStatus(BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
noticeCarStatus(); |
|
|
|
|
noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -90,9 +86,7 @@ public class SendCommandService { |
|
|
|
|
* @param channelNo |
|
|
|
|
*/ |
|
|
|
|
public boolean sendToDevice(String clientId, Integer channelNo) { |
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(clientId); |
|
|
|
|
BusinessCacheUtil.setPushStatus(BusinessConstant.LIVE_STATUS_WAITING); |
|
|
|
|
noticeCarStatus(); |
|
|
|
|
noticeCarStatus(clientId, channelNo, BusinessConstant.LIVE_STATUS_WAITING); |
|
|
|
|
|
|
|
|
|
// 判断该设备是否为在线设备
|
|
|
|
|
Session session = sessionManager.get(clientId); |
|
|
|
|
@ -103,9 +97,7 @@ public class SendCommandService { |
|
|
|
|
|
|
|
|
|
if (!sendCommand(clientId, channelNo)) { |
|
|
|
|
// 若推流命令发送失败, 设备设置为离线
|
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(null); |
|
|
|
|
BusinessCacheUtil.setPushStatus(BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
noticeCarStatus(); |
|
|
|
|
noticeCarStatus(null, channelNo, BusinessConstant.LIVE_STATUS_OFFLINE); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -113,7 +105,6 @@ public class SendCommandService { |
|
|
|
|
private boolean sendCommand(String clientId, Integer channelNo) { |
|
|
|
|
channelNo = channelNo == null ? BusinessConstant.DEFAULT_CHANNEL_NO : channelNo; |
|
|
|
|
|
|
|
|
|
log.info("*********** 自定义发送实时音视频传输请求 start"); |
|
|
|
|
try { |
|
|
|
|
// step1: 向车载机发送命令
|
|
|
|
|
T9101 request = new T9101(); |
|
|
|
|
@ -124,10 +115,12 @@ public class SendCommandService { |
|
|
|
|
request.setStreamType(0); |
|
|
|
|
request.setTcpPort(4001); |
|
|
|
|
request.setUdpPort(0); |
|
|
|
|
log.info("*** 发送实时音视频传输请求 start. request params : " + request.toString()); |
|
|
|
|
Mono<APIResult<T0001>> resultMono = messageManager.requestR(request, T0001.class); |
|
|
|
|
log.info("*********** 自定义发送实时音视频传输请求 t0102 : " + resultMono.block().isSuccess()); |
|
|
|
|
APIResult<T0001> resultObj = resultMono.block(); |
|
|
|
|
log.info("*** 发送实时音视频传输请求 result : " + resultObj.toString()); |
|
|
|
|
|
|
|
|
|
boolean sendResult = resultMono.block().isSuccess(); |
|
|
|
|
boolean sendResult = resultObj.isSuccess(); |
|
|
|
|
// 若命令发送失败, 返回false
|
|
|
|
|
if (!sendResult) { |
|
|
|
|
return false; |
|
|
|
|
@ -138,15 +131,13 @@ public class SendCommandService { |
|
|
|
|
|
|
|
|
|
// step3: 调用3次, 失败后等待1s, 继续调用3次. 若仍然失败, 视为命令发送失败, 返回false
|
|
|
|
|
int times = 0; |
|
|
|
|
while (times < 2) { |
|
|
|
|
while (times < 3) { |
|
|
|
|
// 调用jtt1078流媒体接口
|
|
|
|
|
String clientId1078 = BusinessCacheUtil.get1078PushDevice(); |
|
|
|
|
|
|
|
|
|
// 判断返回的推流设备是否为发送命令的设备, 如果是, 返回true, 否则继续下次循环
|
|
|
|
|
if (clientId.equals(clientId1078)) { |
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(clientId); |
|
|
|
|
BusinessCacheUtil.setPushStatus(BusinessConstant.LIVE_STATUS_ONLINE); |
|
|
|
|
noticeCarStatus(); |
|
|
|
|
noticeCarStatus(clientId, channelNo, BusinessConstant.LIVE_STATUS_ONLINE); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -159,15 +150,20 @@ public class SendCommandService { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void noticeCarStatus(String clientId, Integer channelNo, String status) { |
|
|
|
|
channelNo = channelNo == null ? BusinessConstant.DEFAULT_CHANNEL_NO : channelNo; |
|
|
|
|
|
|
|
|
|
// 更新推流车辆和推流状态
|
|
|
|
|
BusinessCacheUtil.setCurrentPushDevice(clientId); |
|
|
|
|
BusinessCacheUtil.setCurrentPushChannel(channelNo); |
|
|
|
|
BusinessCacheUtil.setPushStatus(status); |
|
|
|
|
|
|
|
|
|
public void noticeCarStatus() { |
|
|
|
|
String clientId = BusinessCacheUtil.getCurrentPushDevice(); |
|
|
|
|
String status = BusinessCacheUtil.getPushStatus(); |
|
|
|
|
// 设备注册后, 调用接口通知给web服务器
|
|
|
|
|
String url = "http://127.0.0.1:8002/blade-business/common-api/set-car-stat"; |
|
|
|
|
// 调用接口通知给慢直播服务器
|
|
|
|
|
String url = BusinessConstant.LIVE_SERVER_UPDATE_PUSH_CAR; |
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
params.put("clientId", clientId); |
|
|
|
|
params.put("carStat", status); |
|
|
|
|
log.info(">>> notice to poc-live. url = " + url + " | params = " + params.toString()); |
|
|
|
|
HttpClientUtils.doGet(url, params); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|