
16 changed files with 416 additions and 13 deletions
@ -0,0 +1,21 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; |
||||
|
|
||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
||||
|
import org.springframework.context.ApplicationEvent; |
||||
|
|
||||
|
public class PlatformNotRegisterEvent extends ApplicationEvent { |
||||
|
|
||||
|
private String platformGbID; |
||||
|
|
||||
|
public PlatformNotRegisterEvent(Object source) { |
||||
|
super(source); |
||||
|
} |
||||
|
|
||||
|
public String getPlatformGbID() { |
||||
|
return platformGbID; |
||||
|
} |
||||
|
|
||||
|
public void setPlatformGbID(String platformGbID) { |
||||
|
this.platformGbID = platformGbID; |
||||
|
} |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; |
||||
|
|
||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
||||
|
import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent; |
||||
|
import com.genersoft.iot.vmp.gb28181.event.online.OnlineEventListener; |
||||
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
||||
|
import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.context.ApplicationEvent; |
||||
|
import org.springframework.context.ApplicationListener; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @Description: 平台未注册事件,来源有二: |
||||
|
* 1、平台新添加 |
||||
|
* 2、平台心跳超时 |
||||
|
* @author: panll |
||||
|
* @date: 2020年11月24日 10:00 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class PlatformNotRegisterEventLister implements ApplicationListener<PlatformNotRegisterEvent> { |
||||
|
|
||||
|
private final static Logger logger = LoggerFactory.getLogger(PlatformNotRegisterEventLister.class); |
||||
|
|
||||
|
@Autowired |
||||
|
private IVideoManagerStorager storager; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisUtil redis; |
||||
|
|
||||
|
@Override |
||||
|
public void onApplicationEvent(PlatformNotRegisterEvent event) { |
||||
|
|
||||
|
if (logger.isDebugEnabled()) { |
||||
|
logger.debug("平台未注册事件触发,平台国标ID:" + event.getPlatformGbID()); |
||||
|
} |
||||
|
ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID()); |
||||
|
if (parentPlatform == null) { |
||||
|
logger.debug("平台未注册事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.transmit.cmd; |
||||
|
|
||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
||||
|
|
||||
|
public interface ISIPCommanderForPlatform { |
||||
|
|
||||
|
/** |
||||
|
* 向上级平台注册 |
||||
|
* @param parentPlatform |
||||
|
* @return |
||||
|
*/ |
||||
|
boolean register(ParentPlatform parentPlatform, String callId, String realm, String nonce, String scheme); |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; |
||||
|
|
||||
|
import com.genersoft.iot.vmp.conf.SipConfig; |
||||
|
import com.genersoft.iot.vmp.gb28181.bean.Device; |
||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
||||
|
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; |
||||
|
import com.genersoft.iot.vmp.media.zlm.ZLMUtils; |
||||
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.lang.Nullable; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.sip.*; |
||||
|
import javax.sip.message.Request; |
||||
|
import java.text.ParseException; |
||||
|
|
||||
|
@Component |
||||
|
public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
||||
|
|
||||
|
@Autowired |
||||
|
private SipConfig sipConfig; |
||||
|
|
||||
|
@Autowired |
||||
|
private SIPRequestHeaderProvider headerProvider; |
||||
|
|
||||
|
@Autowired |
||||
|
private VideoStreamSessionManager streamSession; |
||||
|
|
||||
|
@Autowired |
||||
|
private IVideoManagerStorager storager; |
||||
|
|
||||
|
@Autowired |
||||
|
@Qualifier(value="tcpSipProvider") |
||||
|
private SipProvider tcpSipProvider; |
||||
|
|
||||
|
@Autowired |
||||
|
@Qualifier(value="udpSipProvider") |
||||
|
private SipProvider udpSipProvider; |
||||
|
|
||||
|
@Autowired |
||||
|
private ZLMUtils zlmUtils; |
||||
|
|
||||
|
@Value("${media.rtp.enable}") |
||||
|
private boolean rtpEnable; |
||||
|
|
||||
|
@Override |
||||
|
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable String realm, @Nullable String nonce, @Nullable String scheme ) { |
||||
|
try { |
||||
|
Request request = null; |
||||
|
if (realm == null || nonce == null) { |
||||
|
request = headerProvider.createRegisterRequest(parentPlatform, null, null); |
||||
|
}else { |
||||
|
request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme); |
||||
|
} |
||||
|
|
||||
|
transmitRequest(parentPlatform, request); |
||||
|
return true; |
||||
|
} catch (ParseException e) { |
||||
|
e.printStackTrace(); |
||||
|
} catch (InvalidArgumentException e) { |
||||
|
e.printStackTrace(); |
||||
|
} catch (PeerUnavailableException e) { |
||||
|
e.printStackTrace(); |
||||
|
} catch (SipException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException { |
||||
|
if("TCP".equals(parentPlatform.getTransport())) { |
||||
|
tcpSipProvider.sendRequest(request); |
||||
|
} else if("UDP".equals(parentPlatform.getTransport())) { |
||||
|
udpSipProvider.sendRequest(request); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.transmit.response.impl; |
||||
|
|
||||
|
import com.genersoft.iot.vmp.conf.SipConfig; |
||||
|
import com.genersoft.iot.vmp.gb28181.SipLayer; |
||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
||||
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
||||
|
import gov.nist.core.Host; |
||||
|
import gov.nist.javax.sip.address.AddressImpl; |
||||
|
import gov.nist.javax.sip.address.SipUri; |
||||
|
import gov.nist.javax.sip.header.To; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.sip.ResponseEvent; |
||||
|
import javax.sip.address.Address; |
||||
|
import javax.sip.address.URI; |
||||
|
import javax.sip.header.CallIdHeader; |
||||
|
import javax.sip.header.ToHeader; |
||||
|
import javax.sip.header.WWWAuthenticateHeader; |
||||
|
import javax.sip.message.Response; |
||||
|
|
||||
|
/** |
||||
|
* @Description:Register响应处理器 |
||||
|
* @author: swwheihei |
||||
|
* @date: 2020年5月3日 下午5:32:23 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class RegisterResponseProcessor implements ISIPResponseProcessor { |
||||
|
|
||||
|
private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class); |
||||
|
|
||||
|
@Autowired |
||||
|
private ISIPCommanderForPlatform sipCommanderForPlatform; |
||||
|
|
||||
|
@Autowired |
||||
|
private IVideoManagerStorager storager; |
||||
|
|
||||
|
/** |
||||
|
* 处理Register响应 |
||||
|
* |
||||
|
* @param evt |
||||
|
* @param layer |
||||
|
* @param config |
||||
|
*/ |
||||
|
@Override |
||||
|
public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { |
||||
|
// TODO Auto-generated method stub
|
||||
|
Response response = evt.getResponse(); |
||||
|
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); |
||||
|
SipUri uri = (SipUri)toHeader.getAddress().getURI(); |
||||
|
String platformGBId = uri.getAuthority().getUser(); |
||||
|
logger.info(String.format("收到 %s 的注册%S请求", platformGBId, response.getStatusCode() )); |
||||
|
|
||||
|
ParentPlatform parentPlatform = storager.queryParentPlatById(platformGBId); |
||||
|
if (parentPlatform == null) { |
||||
|
logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode())); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (response.getStatusCode() == 401) { |
||||
|
|
||||
|
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME); |
||||
|
String realm = www.getRealm(); |
||||
|
String nonce = www.getNonce(); |
||||
|
String scheme = www.getScheme(); |
||||
|
|
||||
|
CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME); |
||||
|
String callId = callIdHeader.getCallId(); |
||||
|
sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme); |
||||
|
}else if (response.getStatusCode() == 200){ |
||||
|
// 注册成功
|
||||
|
logger.info(String.format("%s 注册成功", platformGBId )); |
||||
|
parentPlatform.setStatus(true); |
||||
|
storager.updateParentPlatform(parentPlatform); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue