|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.gb28181; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.SipConfig; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetting; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.conf.DefaultProperties; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver; | 
|---|
|  |  |  | import gov.nist.javax.sip.SipProviderImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.concurrent.ConcurrentHashMap; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | @Order(value=1) | 
|---|
|  |  |  | @Order(value=10) | 
|---|
|  |  |  | public class SipLayer implements CommandLineRunner { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ISIPProcessorObserver sipProcessorObserver; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final Map<String, SipProviderImpl> tcpSipProviderMap = new ConcurrentHashMap<>(); | 
|---|
|  |  |  | private final Map<String, SipProviderImpl> udpSipProviderMap = new ConcurrentHashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private SipFactory sipFactory; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void run(String... args) { | 
|---|
|  |  |  | 
|---|
|  |  |  | monitorIps.add(sipConfig.getIp()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sipFactory = SipFactory.getInstance(); | 
|---|
|  |  |  | sipFactory.setPathName("gov.nist"); | 
|---|
|  |  |  | SipFactory.getInstance().setPathName("gov.nist"); | 
|---|
|  |  |  | if (monitorIps.size() > 0) { | 
|---|
|  |  |  | for (String monitorIp : monitorIps) { | 
|---|
|  |  |  | addListeningPoint(monitorIp, sipConfig.getPort()); | 
|---|
|  |  |  | 
|---|
|  |  |  | private void addListeningPoint(String monitorIp, int port){ | 
|---|
|  |  |  | SipStackImpl sipStack; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | sipStack = (SipStackImpl)sipFactory.createSipStack(DefaultProperties.getProperties(monitorIp, false)); | 
|---|
|  |  |  | sipStack = (SipStackImpl)SipFactory.getInstance().createSipStack(DefaultProperties.getProperties(monitorIp, userSetting.getSipLog())); | 
|---|
|  |  |  | } catch (PeerUnavailableException e) { | 
|---|
|  |  |  | logger.error("[Sip Server] SIP服务启动失败, 监听地址{}失败,请检查ip是否正确", monitorIp); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.error("[Sip Server] udp://{}:{} SIP服务启动失败,请检查端口是否被占用或者ip是否正确" | 
|---|
|  |  |  | , monitorIp, port); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public SipFactory getSipFactory() { | 
|---|
|  |  |  | return sipFactory; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public SipProviderImpl getUdpSipProvider(String ip) { | 
|---|