| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.DynamicTask; |
| | | import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch; |
| | | import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatchStatus; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| | | import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| | | import com.genersoft.iot.vmp.service.IPlayService; |
| | | import gov.nist.javax.sip.message.SIPRequest; |
| | | import org.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | |
| | | private ResponseMessageHandler responseMessageHandler; |
| | | |
| | | @Autowired |
| | | private DeferredResultHolder deferredResultHolder; |
| | | private DynamicTask dynamicTask; |
| | | |
| | | @Autowired |
| | | private AudioBroadcastManager audioBroadcastManager; |
| | | |
| | | @Autowired |
| | | private IPlayService playService; |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | |
| | | |
| | | @Override |
| | | public void handForDevice(RequestEvent evt, Device device, Element rootElement) { |
| | | |
| | | SIPRequest request = (SIPRequest) evt.getRequest(); |
| | | try { |
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + device.getDeviceId() + channelId; |
| | | // 回复200 OK |
| | | responseAck((SIPRequest) evt.getRequest(), Response.OK); |
| | | // 此处是对本平台发出Broadcast指令的应答 |
| | | JSONObject json = new JSONObject(); |
| | | XmlUtil.node2Json(rootElement, json); |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug(json.toJSONString()); |
| | | if (!audioBroadcastManager.exit(device.getDeviceId(), channelId)) { |
| | | // 回复410 |
| | | responseAck((SIPRequest) evt.getRequest(), Response.GONE); |
| | | return; |
| | | } |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setKey(key); |
| | | msg.setData(json); |
| | | deferredResultHolder.invokeAllResult(msg); |
| | | String result = getText(rootElement, "Result"); |
| | | Element infoElement = rootElement.element("Info"); |
| | | String reason = null; |
| | | if (infoElement != null) { |
| | | reason = getText(infoElement, "Reason"); |
| | | } |
| | | logger.info("[语音广播]回复:{}, {}/{}", reason == null? result : result + ": " + reason, device.getDeviceId(), channelId ); |
| | | |
| | | |
| | | // 回复200 OK |
| | | responseAck(request, Response.OK); |
| | | if (result.equalsIgnoreCase("OK")) { |
| | | AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(device.getDeviceId(), channelId); |
| | | audioBroadcastCatch.setStatus(AudioBroadcastCatchStatus.WaiteInvite); |
| | | audioBroadcastManager.update(audioBroadcastCatch); |
| | | }else { |
| | | playService.stopAudioBroadcast(device.getDeviceId(), channelId); |
| | | } |
| | | } catch (ParseException | SipException | InvalidArgumentException e) { |
| | | logger.error("[命令发送失败] 国标级联 语音喊话: {}", e.getMessage()); |
| | | } |