|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.DynamicTask; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.SipConfig; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SipConfig config; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DynamicTask dynamicTask; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // @Autowired | 
|---|
|  |  |  | // private RedisUtil redis; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流size", sendRtpItems.size()); | 
|---|
|  |  |  | if (sendRtpItems != null && sendRtpItems.size() > 0) { | 
|---|
|  |  |  | logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID()); | 
|---|
|  |  |  | StringBuilder app = new StringBuilder(); | 
|---|
|  |  |  | StringBuilder stream = new StringBuilder(); | 
|---|
|  |  |  | for (SendRtpItem sendRtpItem : sendRtpItems) { | 
|---|
|  |  |  | if (app.length() != 0) { | 
|---|
|  |  |  | app.append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | app.append(sendRtpItem.getApp()); | 
|---|
|  |  |  | if (stream.length() != 0) { | 
|---|
|  |  |  | stream.append(","); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | stream.append(sendRtpItem.getStreamId()); | 
|---|
|  |  |  | redisCatchStorage.deleteSendRTPServer(event.getPlatformGbID(), sendRtpItem.getChannelId(), null, null); | 
|---|
|  |  |  | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); | 
|---|
|  |  |  | Map<String, Object> param = new HashMap<>(); | 
|---|
|  |  |  | param.put("vhost", "__defaultVhost__"); | 
|---|
|  |  |  | param.put("app", app.toString()); | 
|---|
|  |  |  | param.put("stream", stream.toString()); | 
|---|
|  |  |  | param.put("app", sendRtpItem.getApp()); | 
|---|
|  |  |  | param.put("stream", sendRtpItem.getStreamId()); | 
|---|
|  |  |  | zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Timer timer = new Timer(); | 
|---|
|  |  |  | String taskKey = "platform-not-register-" + parentPlatform.getServerGBId(); | 
|---|
|  |  |  | SipSubscribe.Event okEvent = (responseEvent)->{ | 
|---|
|  |  |  | timer.cancel(); | 
|---|
|  |  |  | dynamicTask.stop(taskKey); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | logger.info("[平台注册]平台国标ID:" + event.getPlatformGbID()); | 
|---|
|  |  |  | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | 
|---|
|  |  |  | // 设置注册失败则每隔15秒发起一次注册 | 
|---|
|  |  |  | timer.schedule(new TimerTask() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void run() { | 
|---|
|  |  |  | logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | 
|---|
|  |  |  | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册 | 
|---|
|  |  |  | dynamicTask.startCron(taskKey, ()->{ | 
|---|
|  |  |  | logger.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); | 
|---|
|  |  |  | sipCommanderFroPlatform.register(parentPlatform, null, okEvent); | 
|---|
|  |  |  | }, config.getRegisterTimeInterval()* 1000); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|