Commit ecaf8750dd9c537e581ae05c65be9a26db5e67a7
1 parent
2fb203e1
完成向上级联->注册
Showing
16 changed files
with
416 additions
and
13 deletions
README.md
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
| ... | ... | @@ -123,7 +123,7 @@ public class SipLayer implements SipListener { |
| 123 | 123 | public void processResponse(ResponseEvent evt) { |
| 124 | 124 | Response response = evt.getResponse(); |
| 125 | 125 | int status = response.getStatusCode(); |
| 126 | - if ((status >= 200) && (status < 300)) { // Success! | |
| 126 | + if (((status >= 200) && (status < 300)) || status == 401) { // Success! | |
| 127 | 127 | ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); |
| 128 | 128 | try { |
| 129 | 129 | processor.process(evt, this, sipConfig); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent; | |
| 5 | +import com.genersoft.iot.vmp.vmanager.platform.PlatformController; | |
| 3 | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | 7 | import org.springframework.context.ApplicationEventPublisher; |
| 5 | 8 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -31,4 +34,14 @@ public class EventPublisher { |
| 31 | 34 | outEvent.setFrom(from); |
| 32 | 35 | applicationEventPublisher.publishEvent(outEvent); |
| 33 | 36 | } |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 平台未注册事件 | |
| 40 | + * @param platformGbId | |
| 41 | + */ | |
| 42 | + public void platformNotRegisterEventPublish(String platformGbId){ | |
| 43 | + PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this); | |
| 44 | + platformNotRegisterEvent.setPlatformGbID(platformGbId); | |
| 45 | + applicationEventPublisher.publishEvent(platformNotRegisterEvent); | |
| 46 | + } | |
| 34 | 47 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEvent.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 4 | +import org.springframework.context.ApplicationEvent; | |
| 5 | + | |
| 6 | +public class PlatformNotRegisterEvent extends ApplicationEvent { | |
| 7 | + | |
| 8 | + private String platformGbID; | |
| 9 | + | |
| 10 | + public PlatformNotRegisterEvent(Object source) { | |
| 11 | + super(source); | |
| 12 | + } | |
| 13 | + | |
| 14 | + public String getPlatformGbID() { | |
| 15 | + return platformGbID; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public void setPlatformGbID(String platformGbID) { | |
| 19 | + this.platformGbID = platformGbID; | |
| 20 | + } | |
| 21 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.event.online.OnlineEventListener; | |
| 6 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 7 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 8 | +import org.slf4j.Logger; | |
| 9 | +import org.slf4j.LoggerFactory; | |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | +import org.springframework.context.ApplicationEvent; | |
| 12 | +import org.springframework.context.ApplicationListener; | |
| 13 | +import org.springframework.stereotype.Component; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * @Description: 平台未注册事件,来源有二: | |
| 17 | + * 1、平台新添加 | |
| 18 | + * 2、平台心跳超时 | |
| 19 | + * @author: panll | |
| 20 | + * @date: 2020年11月24日 10:00 | |
| 21 | + */ | |
| 22 | +@Component | |
| 23 | +public class PlatformNotRegisterEventLister implements ApplicationListener<PlatformNotRegisterEvent> { | |
| 24 | + | |
| 25 | + private final static Logger logger = LoggerFactory.getLogger(PlatformNotRegisterEventLister.class); | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private IVideoManagerStorager storager; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private RedisUtil redis; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void onApplicationEvent(PlatformNotRegisterEvent event) { | |
| 35 | + | |
| 36 | + if (logger.isDebugEnabled()) { | |
| 37 | + logger.debug("平台未注册事件触发,平台国标ID:" + event.getPlatformGbID()); | |
| 38 | + } | |
| 39 | + ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID()); | |
| 40 | + if (parentPlatform == null) { | |
| 41 | + logger.debug("平台未注册事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); | |
| 42 | + return; | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
| ... | ... | @@ -8,6 +8,7 @@ import javax.sip.message.Request; |
| 8 | 8 | import javax.sip.message.Response; |
| 9 | 9 | |
| 10 | 10 | import com.alibaba.fastjson.JSON; |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*; | |
| 11 | 12 | import org.slf4j.Logger; |
| 12 | 13 | import org.slf4j.LoggerFactory; |
| 13 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -30,10 +31,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.impl.OtherRequestProcessor |
| 30 | 31 | import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor; |
| 31 | 32 | import com.genersoft.iot.vmp.gb28181.transmit.request.impl.SubscribeRequestProcessor; |
| 32 | 33 | import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
| 33 | -import com.genersoft.iot.vmp.gb28181.transmit.response.impl.ByeResponseProcessor; | |
| 34 | -import com.genersoft.iot.vmp.gb28181.transmit.response.impl.CancelResponseProcessor; | |
| 35 | -import com.genersoft.iot.vmp.gb28181.transmit.response.impl.InviteResponseProcessor; | |
| 36 | -import com.genersoft.iot.vmp.gb28181.transmit.response.impl.OtherResponseProcessor; | |
| 37 | 34 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 38 | 35 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; |
| 39 | 36 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| ... | ... | @@ -80,6 +77,9 @@ public class SIPProcessorFactory { |
| 80 | 77 | |
| 81 | 78 | @Autowired |
| 82 | 79 | private CancelResponseProcessor cancelResponseProcessor; |
| 80 | + | |
| 81 | + @Autowired | |
| 82 | + private RegisterResponseProcessor registerResponseProcessor; | |
| 83 | 83 | |
| 84 | 84 | @Autowired |
| 85 | 85 | private OtherResponseProcessor otherResponseProcessor; |
| ... | ... | @@ -154,6 +154,8 @@ public class SIPProcessorFactory { |
| 154 | 154 | return byeResponseProcessor; |
| 155 | 155 | } else if (Request.CANCEL.equals(method)) { |
| 156 | 156 | return cancelResponseProcessor; |
| 157 | + }else if (Request.REGISTER.equals(method)) { | |
| 158 | + return registerResponseProcessor; | |
| 157 | 159 | } else { |
| 158 | 160 | return otherResponseProcessor; |
| 159 | 161 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
| ... | ... | @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * @Description:设备能力接口,用于定义设备的控制、查询能力 |
| ... | ... | @@ -212,4 +213,6 @@ public interface ISIPCommander { |
| 212 | 213 | * @param device 视频设备 |
| 213 | 214 | */ |
| 214 | 215 | public boolean mobilePostitionQuery(Device device); |
| 216 | + | |
| 217 | + | |
| 215 | 218 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 4 | + | |
| 5 | +public interface ISIPCommanderForPlatform { | |
| 6 | + | |
| 7 | + /** | |
| 8 | + * 向上级平台注册 | |
| 9 | + * @param parentPlatform | |
| 10 | + * @return | |
| 11 | + */ | |
| 12 | + boolean register(ParentPlatform parentPlatform, String callId, String realm, String nonce, String scheme); | |
| 13 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
| ... | ... | @@ -11,7 +11,9 @@ import javax.sip.address.Address; |
| 11 | 11 | import javax.sip.address.SipURI; |
| 12 | 12 | import javax.sip.header.*; |
| 13 | 13 | import javax.sip.message.Request; |
| 14 | +import javax.validation.constraints.NotNull; | |
| 14 | 15 | |
| 16 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 15 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | 18 | import org.springframework.beans.factory.annotation.Qualifier; |
| 17 | 19 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -19,6 +21,7 @@ import org.springframework.stereotype.Component; |
| 19 | 21 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 20 | 22 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 21 | 23 | import com.genersoft.iot.vmp.gb28181.bean.Host; |
| 24 | +import org.springframework.util.DigestUtils; | |
| 22 | 25 | |
| 23 | 26 | /** |
| 24 | 27 | * @Description:摄像头命令request创造器 TODO 冗余代码太多待优化 |
| ... | ... | @@ -168,4 +171,73 @@ public class SIPRequestHeaderProvider { |
| 168 | 171 | request.setContent(content, contentTypeHeader); |
| 169 | 172 | return request; |
| 170 | 173 | } |
| 174 | + | |
| 175 | + | |
| 176 | + public Request createRegisterRequest(@NotNull ParentPlatform platform, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException { | |
| 177 | + Request request = null; | |
| 178 | + String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort(); | |
| 179 | + //请求行 | |
| 180 | + SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(), | |
| 181 | + platform.getServerIP() + ":" + platform.getServerPort()); | |
| 182 | + //via | |
| 183 | + ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); | |
| 184 | + ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(platform.getServerIP(), platform.getServerPort(), platform.getTransport(), viaTag); | |
| 185 | + viaHeader.setRPort(); | |
| 186 | + viaHeaders.add(viaHeader); | |
| 187 | + //from | |
| 188 | + SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress); | |
| 189 | + Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); | |
| 190 | + FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); | |
| 191 | + //to | |
| 192 | + SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress); | |
| 193 | + Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); | |
| 194 | + ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); | |
| 195 | + | |
| 196 | + //callid | |
| 197 | + CallIdHeader callIdHeader = null; | |
| 198 | + if(platform.getTransport().equals("TCP")) { | |
| 199 | + callIdHeader = tcpSipProvider.getNewCallId(); | |
| 200 | + } | |
| 201 | + if(platform.getTransport().equals("UDP")) { | |
| 202 | + callIdHeader = udpSipProvider.getNewCallId(); | |
| 203 | + } | |
| 204 | + | |
| 205 | + //Forwards | |
| 206 | + MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); | |
| 207 | + | |
| 208 | + //ceq | |
| 209 | + CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.REGISTER); | |
| 210 | + request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader, | |
| 211 | + cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); | |
| 212 | + | |
| 213 | + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() | |
| 214 | + .createSipURI(platform.getDeviceGBId(), sipAddress)); | |
| 215 | + request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); | |
| 216 | + | |
| 217 | + return request; | |
| 218 | + } | |
| 219 | + | |
| 220 | + public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag, | |
| 221 | + String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException { | |
| 222 | + Request registerRequest = createRegisterRequest(parentPlatform, fromTag, viaTag); | |
| 223 | + | |
| 224 | + CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME); | |
| 225 | + callIdHeader.setCallId(callId); | |
| 226 | + | |
| 227 | + String uri = "sip:" + parentPlatform.getServerGBId() + | |
| 228 | + "@" + parentPlatform.getServerIP() + | |
| 229 | + ":" + parentPlatform.getServerPort(); | |
| 230 | + | |
| 231 | + String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes()); | |
| 232 | + String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes()); | |
| 233 | + String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes()); | |
| 234 | + | |
| 235 | + String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\"" | |
| 236 | + + realm + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\", nonce=\"" | |
| 237 | + + nonce + "\""; | |
| 238 | + AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent); | |
| 239 | + registerRequest.addHeader(authorizationHeader); | |
| 240 | + | |
| 241 | + return registerRequest; | |
| 242 | + } | |
| 171 | 243 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; | |
| 9 | +import com.genersoft.iot.vmp.media.zlm.ZLMUtils; | |
| 10 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 13 | +import org.springframework.beans.factory.annotation.Value; | |
| 14 | +import org.springframework.lang.Nullable; | |
| 15 | +import org.springframework.stereotype.Component; | |
| 16 | + | |
| 17 | +import javax.sip.*; | |
| 18 | +import javax.sip.message.Request; | |
| 19 | +import java.text.ParseException; | |
| 20 | + | |
| 21 | +@Component | |
| 22 | +public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + private SipConfig sipConfig; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private SIPRequestHeaderProvider headerProvider; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private VideoStreamSessionManager streamSession; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + private IVideoManagerStorager storager; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + @Qualifier(value="tcpSipProvider") | |
| 38 | + private SipProvider tcpSipProvider; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + @Qualifier(value="udpSipProvider") | |
| 42 | + private SipProvider udpSipProvider; | |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + private ZLMUtils zlmUtils; | |
| 46 | + | |
| 47 | + @Value("${media.rtp.enable}") | |
| 48 | + private boolean rtpEnable; | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable String realm, @Nullable String nonce, @Nullable String scheme ) { | |
| 52 | + try { | |
| 53 | + Request request = null; | |
| 54 | + if (realm == null || nonce == null) { | |
| 55 | + request = headerProvider.createRegisterRequest(parentPlatform, null, null); | |
| 56 | + }else { | |
| 57 | + request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme); | |
| 58 | + } | |
| 59 | + | |
| 60 | + transmitRequest(parentPlatform, request); | |
| 61 | + return true; | |
| 62 | + } catch (ParseException e) { | |
| 63 | + e.printStackTrace(); | |
| 64 | + } catch (InvalidArgumentException e) { | |
| 65 | + e.printStackTrace(); | |
| 66 | + } catch (PeerUnavailableException e) { | |
| 67 | + e.printStackTrace(); | |
| 68 | + } catch (SipException e) { | |
| 69 | + e.printStackTrace(); | |
| 70 | + } | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | + | |
| 74 | + private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException { | |
| 75 | + if("TCP".equals(parentPlatform.getTransport())) { | |
| 76 | + tcpSipProvider.sendRequest(request); | |
| 77 | + } else if("UDP".equals(parentPlatform.getTransport())) { | |
| 78 | + udpSipProvider.sendRequest(request); | |
| 79 | + } | |
| 80 | + } | |
| 81 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.response.impl; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.SipLayer; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; | |
| 9 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 10 | +import gov.nist.core.Host; | |
| 11 | +import gov.nist.javax.sip.address.AddressImpl; | |
| 12 | +import gov.nist.javax.sip.address.SipUri; | |
| 13 | +import gov.nist.javax.sip.header.To; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import javax.sip.ResponseEvent; | |
| 20 | +import javax.sip.address.Address; | |
| 21 | +import javax.sip.address.URI; | |
| 22 | +import javax.sip.header.CallIdHeader; | |
| 23 | +import javax.sip.header.ToHeader; | |
| 24 | +import javax.sip.header.WWWAuthenticateHeader; | |
| 25 | +import javax.sip.message.Response; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * @Description:Register响应处理器 | |
| 29 | + * @author: swwheihei | |
| 30 | + * @date: 2020年5月3日 下午5:32:23 | |
| 31 | + */ | |
| 32 | +@Component | |
| 33 | +public class RegisterResponseProcessor implements ISIPResponseProcessor { | |
| 34 | + | |
| 35 | + private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class); | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private ISIPCommanderForPlatform sipCommanderForPlatform; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private IVideoManagerStorager storager; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 处理Register响应 | |
| 45 | + * | |
| 46 | + * @param evt | |
| 47 | + * @param layer | |
| 48 | + * @param config | |
| 49 | + */ | |
| 50 | + @Override | |
| 51 | + public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { | |
| 52 | + // TODO Auto-generated method stub | |
| 53 | + Response response = evt.getResponse(); | |
| 54 | + ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); | |
| 55 | + SipUri uri = (SipUri)toHeader.getAddress().getURI(); | |
| 56 | + String platformGBId = uri.getAuthority().getUser(); | |
| 57 | + logger.info(String.format("收到 %s 的注册%S请求", platformGBId, response.getStatusCode() )); | |
| 58 | + | |
| 59 | + ParentPlatform parentPlatform = storager.queryParentPlatById(platformGBId); | |
| 60 | + if (parentPlatform == null) { | |
| 61 | + logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode())); | |
| 62 | + return; | |
| 63 | + } | |
| 64 | + | |
| 65 | + if (response.getStatusCode() == 401) { | |
| 66 | + | |
| 67 | + WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME); | |
| 68 | + String realm = www.getRealm(); | |
| 69 | + String nonce = www.getNonce(); | |
| 70 | + String scheme = www.getScheme(); | |
| 71 | + | |
| 72 | + CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME); | |
| 73 | + String callId = callIdHeader.getCallId(); | |
| 74 | + sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme); | |
| 75 | + }else if (response.getStatusCode() == 200){ | |
| 76 | + // 注册成功 | |
| 77 | + logger.info(String.format("%s 注册成功", platformGBId )); | |
| 78 | + parentPlatform.setStatus(true); | |
| 79 | + storager.updateParentPlatform(parentPlatform); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
| ... | ... | @@ -213,4 +213,11 @@ public interface IVideoManagerStorager { |
| 213 | 213 | * @return |
| 214 | 214 | */ |
| 215 | 215 | public PageResult<ParentPlatform> queryParentPlatformList(int page, int count); |
| 216 | + | |
| 217 | + /** | |
| 218 | + * 获取上级平台 | |
| 219 | + * @param platformGbId | |
| 220 | + * @return | |
| 221 | + */ | |
| 222 | + public ParentPlatform queryParentPlatById(String platformGbId); | |
| 216 | 223 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/jdbc/VideoManagerJdbcStoragerImpl.java
| ... | ... | @@ -229,4 +229,9 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { |
| 229 | 229 | public PageResult<ParentPlatform> queryParentPlatformList(int page, int count) { |
| 230 | 230 | return null; |
| 231 | 231 | } |
| 232 | + | |
| 233 | + @Override | |
| 234 | + public ParentPlatform queryParentPlatById(String platformGbId) { | |
| 235 | + return null; | |
| 236 | + } | |
| 232 | 237 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
| ... | ... | @@ -561,6 +561,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { |
| 561 | 561 | |
| 562 | 562 | @Override |
| 563 | 563 | public boolean updateParentPlatform(ParentPlatform parentPlatform) { |
| 564 | + | |
| 564 | 565 | // 存储device |
| 565 | 566 | return redis.set(VideoManagerConstants.PLATFORM_PREFIX + parentPlatform.getDeviceGBId(), parentPlatform); |
| 566 | 567 | } |
| ... | ... | @@ -587,4 +588,9 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { |
| 587 | 588 | pageResult.setData(resultData); |
| 588 | 589 | return pageResult; |
| 589 | 590 | } |
| 591 | + | |
| 592 | + @Override | |
| 593 | + public ParentPlatform queryParentPlatById(String platformGbId) { | |
| 594 | + return (ParentPlatform)redis.get(VideoManagerConstants.PLATFORM_PREFIX + platformGbId); | |
| 595 | + } | |
| 590 | 596 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
| ... | ... | @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.vmanager.platform; |
| 3 | 3 | import com.genersoft.iot.vmp.common.PageResult; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 6 | 8 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 7 | 9 | import com.genersoft.iot.vmp.vmanager.device.DeviceController; |
| 8 | 10 | import org.slf4j.Logger; |
| ... | ... | @@ -24,6 +26,9 @@ public class PlatformController { |
| 24 | 26 | @Autowired |
| 25 | 27 | private IVideoManagerStorager storager; |
| 26 | 28 | |
| 29 | + @Autowired | |
| 30 | + private ISIPCommanderForPlatform commanderForPlatform; | |
| 31 | + | |
| 27 | 32 | @GetMapping("/platforms/{count}/{page}") |
| 28 | 33 | public PageResult<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count){ |
| 29 | 34 | |
| ... | ... | @@ -53,8 +58,13 @@ public class PlatformController { |
| 53 | 58 | ){ |
| 54 | 59 | return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST); |
| 55 | 60 | } |
| 61 | + // TODO 检查是否已经存在,且注册成功, 如果注册成功,需要先注销之前再,修改并注册 | |
| 62 | + | |
| 56 | 63 | boolean updateResult = storager.updateParentPlatform(parentPlatform); |
| 64 | + | |
| 57 | 65 | if (updateResult) { |
| 66 | + commanderForPlatform.register(parentPlatform, null, null, null, null); | |
| 67 | + | |
| 58 | 68 | return new ResponseEntity<>("success", HttpStatus.OK); |
| 59 | 69 | }else { |
| 60 | 70 | return new ResponseEntity<>("fail", HttpStatus.OK); |
| ... | ... | @@ -79,4 +89,17 @@ public class PlatformController { |
| 79 | 89 | return new ResponseEntity<>("fail", HttpStatus.OK); |
| 80 | 90 | } |
| 81 | 91 | } |
| 92 | + | |
| 93 | + @RequestMapping("/platforms/exit/{deviceGbId}") | |
| 94 | + @ResponseBody | |
| 95 | + public ResponseEntity<String> exitPlatform(@PathVariable String deviceGbId){ | |
| 96 | + | |
| 97 | + if (logger.isDebugEnabled()) { | |
| 98 | + logger.debug("查询所有上级设备API调用"); | |
| 99 | + } | |
| 100 | + ParentPlatform parentPlatform = storager.queryParentPlatById(deviceGbId); | |
| 101 | + return new ResponseEntity<>(String.valueOf(parentPlatform != null), HttpStatus.OK); | |
| 102 | + } | |
| 103 | + | |
| 104 | + | |
| 82 | 105 | } | ... | ... |
web_src/src/components/platformEdit.vue
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | <el-form-item label="本地端口" prop="devicePort"> |
| 31 | 31 | <el-input v-model="platform.devicePort" :disabled="true"></el-input> |
| 32 | 32 | </el-form-item> |
| 33 | - | |
| 33 | + | |
| 34 | 34 | </el-form> |
| 35 | 35 | </el-col> |
| 36 | 36 | <el-col :span="12"> |
| ... | ... | @@ -61,8 +61,8 @@ |
| 61 | 61 | </el-form-item> |
| 62 | 62 | <el-form-item label="其他选项" > |
| 63 | 63 | <el-checkbox label="启用" v-model="platform.enable" ></el-checkbox> |
| 64 | - <el-checkbox label="允许云台控制" v-model="platform.PTZEnable"></el-checkbox> | |
| 65 | - <el-checkbox label="启用RTCP保活" v-model="platform.rtcp"></el-checkbox> | |
| 64 | + <el-checkbox label="云台控制" v-model="platform.PTZEnable"></el-checkbox> | |
| 65 | + <el-checkbox label="RTCP保活" v-model="platform.rtcp"></el-checkbox> | |
| 66 | 66 | </el-form-item> |
| 67 | 67 | <el-form-item> |
| 68 | 68 | <el-button type="primary" @click="onSubmit">{{onSubmit_text}}</el-button> |
| ... | ... | @@ -81,10 +81,26 @@ export default { |
| 81 | 81 | name: 'platformEdit', |
| 82 | 82 | props: {}, |
| 83 | 83 | computed: { |
| 84 | - | |
| 84 | + | |
| 85 | 85 | }, |
| 86 | 86 | created() {}, |
| 87 | 87 | data() { |
| 88 | + var deviceGBIdRules = async (rule, value, callback) => { | |
| 89 | + console.log(value) | |
| 90 | + if (value === '') { | |
| 91 | + callback(new Error('请输入设备国标编号')); | |
| 92 | + } else { | |
| 93 | + var exit = await this.deviceGBIdExit(value); | |
| 94 | + console.log(exit) | |
| 95 | + console.log(exit == "true") | |
| 96 | + console.log(exit === "true") | |
| 97 | + if (exit) { | |
| 98 | + callback(new Error('设备国标编号已存在')); | |
| 99 | + }else { | |
| 100 | + callback(); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + }; | |
| 88 | 104 | return { |
| 89 | 105 | listChangeCallback: null, |
| 90 | 106 | showDialog: false, |
| ... | ... | @@ -145,7 +161,7 @@ export default { |
| 145 | 161 | { required: true, message:"请输入SIP服务端口", trigger: 'blur' } |
| 146 | 162 | ], |
| 147 | 163 | deviceGBId: [ |
| 148 | - { required: true, message:"请输入设备国标编号", trigger: 'blur' } | |
| 164 | + {validator: deviceGBIdRules, trigger: 'blur' } | |
| 149 | 165 | ], |
| 150 | 166 | username: [ |
| 151 | 167 | { required: false, message:"请输入SIP认证用户名", trigger: 'blur' } |
| ... | ... | @@ -176,7 +192,7 @@ export default { |
| 176 | 192 | this.platform = platform; |
| 177 | 193 | this.onSubmit_text = "保存" |
| 178 | 194 | } |
| 179 | - | |
| 195 | + | |
| 180 | 196 | }, |
| 181 | 197 | onSubmit: function () { |
| 182 | 198 | console.log('onSubmit'); |
| ... | ... | @@ -206,7 +222,19 @@ export default { |
| 206 | 222 | this.showDialog = false; |
| 207 | 223 | this.$refs.platform1.resetFields(); |
| 208 | 224 | this.$refs.platform2.resetFields(); |
| 209 | - | |
| 225 | + }, | |
| 226 | + deviceGBIdExit: async function (deviceGbId) { | |
| 227 | + var result = false; | |
| 228 | + var that = this | |
| 229 | + await that.$axios.post(`/api/platforms/exit/${deviceGbId}`) | |
| 230 | + .then(function (res) { | |
| 231 | + result = res.data; | |
| 232 | + }) | |
| 233 | + .catch(function (error) { | |
| 234 | + console.log(error); | |
| 235 | + }); | |
| 236 | + return result; | |
| 237 | + | |
| 210 | 238 | } |
| 211 | 239 | |
| 212 | 240 | } | ... | ... |