SipPlatformRunner.java 2.3 KB

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