SipPlatformRunner.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.genersoft.iot.vmp.conf;
  2. import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  3. import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
  4. import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
  5. import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
  6. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  7. import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.boot.CommandLineRunner;
  10. import org.springframework.core.annotation.Order;
  11. import org.springframework.stereotype.Component;
  12. import java.util.List;
  13. /**
  14. * 系统启动时控制上级平台重新注册
  15. */
  16. @Component
  17. @Order(value=3)
  18. public class SipPlatformRunner implements CommandLineRunner {
  19. @Autowired
  20. private IVideoManagerStorage storager;
  21. @Autowired
  22. private IRedisCatchStorage redisCatchStorage;
  23. @Autowired
  24. private EventPublisher publisher;
  25. @Autowired
  26. private ISIPCommanderForPlatform sipCommanderForPlatform;
  27. @Override
  28. public void run(String... args) throws Exception {
  29. // 设置所有平台离线
  30. storager.outlineForAllParentPlatform();
  31. // 清理所有平台注册缓存
  32. redisCatchStorage.cleanPlatformRegisterInfos();
  33. // 停止所有推流
  34. // zlmrtpServerFactory.closeAllSendRtpStream();
  35. List<ParentPlatform> parentPlatforms = storager.queryEnableParentPlatformList(true);
  36. for (ParentPlatform parentPlatform : parentPlatforms) {
  37. redisCatchStorage.updatePlatformRegister(parentPlatform);
  38. redisCatchStorage.updatePlatformKeepalive(parentPlatform);
  39. ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
  40. parentPlatformCatch.setParentPlatform(parentPlatform);
  41. parentPlatformCatch.setId(parentPlatform.getServerGBId());
  42. redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
  43. // 取消订阅
  44. sipCommanderForPlatform.unregister(parentPlatform, null, (eventResult)->{
  45. // 发送平台未注册消息
  46. publisher.platformNotRegisterEventPublish(parentPlatform.getServerGBId());
  47. });
  48. }
  49. }
  50. }