国标28181-支持自动识别网卡监听,可以不再配置SIP.IP
This commit is contained in:
@@ -27,19 +27,19 @@ public class MediaConfig{
|
||||
@Value("${media.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${media.hook-ip:}")
|
||||
private String hookIp;
|
||||
@Value("${media.wan_ip}")
|
||||
private String wanIp;
|
||||
|
||||
@Value("${sip.ip}")
|
||||
private String sipIp;
|
||||
@Value("${media.hook-ip:127.0.0.1}")
|
||||
private String hookIp;
|
||||
|
||||
@Value("${sip.domain}")
|
||||
private String sipDomain;
|
||||
|
||||
@Value("${media.sdp-ip:${media.ip}}")
|
||||
@Value("${media.sdp-ip:${media.wan_ip}}")
|
||||
private String sdpIp;
|
||||
|
||||
@Value("${media.stream-ip:${media.ip}}")
|
||||
@Value("${media.stream-ip:${media.wan_ip}}")
|
||||
private String streamIp;
|
||||
|
||||
@Value("${media.http-port:0}")
|
||||
@@ -111,20 +111,7 @@ public class MediaConfig{
|
||||
}
|
||||
|
||||
public String getHookIp() {
|
||||
if (ObjectUtils.isEmpty(hookIp)){
|
||||
return sipIp;
|
||||
}else {
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getSipIp() {
|
||||
if (sipIp == null) {
|
||||
return this.ip;
|
||||
}else {
|
||||
return sipIp;
|
||||
}
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
public int getHttpPort() {
|
||||
|
||||
@@ -98,9 +98,6 @@ public class SipConfig {
|
||||
}
|
||||
|
||||
public String getShowIp() {
|
||||
if (this.showIp == null) {
|
||||
return this.ip;
|
||||
}
|
||||
return showIp;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class UserSetting {
|
||||
|
||||
private boolean registerKeepIntDialog = false;
|
||||
|
||||
private int gbDeviceOnline = 0;
|
||||
private int gbDeviceOnline = 1;
|
||||
|
||||
public Boolean getSavePositionHistory() {
|
||||
return savePositionHistory;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class WVPTimerTask {
|
||||
@Scheduled(fixedRate = 2 * 1000) //每3秒执行一次
|
||||
public void execute(){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("ip", sipConfig.getIp());
|
||||
jsonObject.put("ip", sipConfig.getShowIp());
|
||||
jsonObject.put("port", serverPort);
|
||||
redisCatchStorage.updateWVPInfo(jsonObject, 3);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.sip.*;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -40,15 +43,46 @@ public class SipLayer implements CommandLineRunner {
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
List<String> monitorIps = new ArrayList<>();
|
||||
// 使用逗号分割多个ip
|
||||
String separator = ",";
|
||||
if (sipConfig.getIp().indexOf(separator) > 0) {
|
||||
String[] split = sipConfig.getIp().split(separator);
|
||||
monitorIps.addAll(Arrays.asList(split));
|
||||
if (ObjectUtils.isEmpty(sipConfig.getIp())) {
|
||||
try {
|
||||
// 获得本机的所有网络接口
|
||||
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
|
||||
while (nifs.hasMoreElements()) {
|
||||
NetworkInterface nif = nifs.nextElement();
|
||||
// 获得与该网络接口绑定的 IP 地址,一般只有一个
|
||||
Enumeration<InetAddress> addresses = nif.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (addr instanceof Inet4Address) {
|
||||
if (addr.getHostAddress().equals("127.0.0.1")){
|
||||
continue;
|
||||
}
|
||||
if (nif.getName().startsWith("docker")) {
|
||||
continue;
|
||||
}
|
||||
logger.error("[自动配置SIP监听网卡] 网卡接口地址: {}", addr.getHostAddress());// 只关心 IPv4 地址
|
||||
monitorIps.add(addr.getHostAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("[读取网卡信息失败]", e);
|
||||
}
|
||||
if (monitorIps.isEmpty()) {
|
||||
logger.error("[自动配置SIP监听网卡信息失败], 请手动配置SIP.IP后重新启动");
|
||||
System.exit(1);
|
||||
}
|
||||
}else {
|
||||
monitorIps.add(sipConfig.getIp());
|
||||
// 使用逗号分割多个ip
|
||||
String separator = ",";
|
||||
if (sipConfig.getIp().indexOf(separator) > 0) {
|
||||
String[] split = sipConfig.getIp().split(separator);
|
||||
monitorIps.addAll(Arrays.asList(split));
|
||||
}else {
|
||||
monitorIps.add(sipConfig.getIp());
|
||||
}
|
||||
}
|
||||
|
||||
sipConfig.setShowIp(String.join(",", monitorIps));
|
||||
SipFactory.getInstance().setPathName("gov.nist");
|
||||
if (monitorIps.size() > 0) {
|
||||
for (String monitorIp : monitorIps) {
|
||||
|
||||
@@ -351,38 +351,6 @@ public class SIPRequestHeaderProvider {
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(gitUtil));
|
||||
|
||||
return request;
|
||||
}
|
||||
public Request createBroadcastMessageRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = SipFactory.getInstance().createAddressFactory().createSipURI(channelId, device.getHostAddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = SipFactory.getInstance().createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag);
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = SipFactory.getInstance().createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = SipFactory.getInstance().createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = SipFactory.getInstance().createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
// to
|
||||
SipURI toSipURI = SipFactory.getInstance().createAddressFactory().createSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = SipFactory.getInstance().createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = SipFactory.getInstance().createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = SipFactory.getInstance().createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = SipFactory.getInstance().createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.MESSAGE);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
|
||||
request = SipFactory.getInstance().createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards, contentTypeHeader, content);
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(gitUtil));
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.genersoft.iot.vmp.media;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class MediaServer {
|
||||
private String ip;
|
||||
|
||||
@Schema(description = "hook使用的IP(zlm访问WVP使用的IP)")
|
||||
private String hookIp;
|
||||
private String hookIp = "127.0.0.1";
|
||||
|
||||
@Schema(description = "SDP IP")
|
||||
private String sdpIp;
|
||||
|
||||
@@ -190,7 +190,15 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
||||
*/
|
||||
// @ResponseBody
|
||||
// @PostMapping(value = "/on_stream_changed", produces = "application/json;charset=UTF-8")
|
||||
// public HookResult onStreamChanged(@RequestBody JSONObject param) {
|
||||
// System.out.println(11);
|
||||
// return HookResult.SUCCESS();
|
||||
// }
|
||||
/**
|
||||
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
||||
*/
|
||||
|
||||
@@ -8,15 +8,14 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -36,9 +35,6 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
@Autowired
|
||||
private ZLMServerFactory zlmServerFactory;
|
||||
|
||||
@Value("${sip.ip}")
|
||||
private String sipIp;
|
||||
|
||||
@Override
|
||||
public int createRTPServer(MediaServer mediaServer, String streamId, long ssrc, Integer port, Boolean onlyAuto, Boolean disableAudio, Boolean reUsePort, Integer tcpMode) {
|
||||
return zlmServerFactory.createRTPServer(mediaServer, streamId, ssrc, port, onlyAuto, reUsePort, tcpMode);
|
||||
@@ -120,7 +116,7 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
mediaServer.setRtpProxyPort(zlmServerConfig.getRtpProxyPort());
|
||||
mediaServer.setStreamIp(ip);
|
||||
|
||||
mediaServer.setHookIp(sipIp.split(",")[0]);
|
||||
mediaServer.setHookIp("127.0.0.1");
|
||||
mediaServer.setSdpIp(ip);
|
||||
mediaServer.setType("zlm");
|
||||
return mediaServer;
|
||||
|
||||
@@ -96,7 +96,6 @@ public class ZLMRESTfulUtils {
|
||||
if (callback == null) {
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody != null) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class PlatformController {
|
||||
@GetMapping("/server_config")
|
||||
public JSONObject serverConfig() {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("deviceIp", sipConfig.getIp());
|
||||
result.put("deviceIp", sipConfig.getShowIp());
|
||||
result.put("devicePort", sipConfig.getPort());
|
||||
result.put("username", sipConfig.getId());
|
||||
result.put("password", sipConfig.getPassword());
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ApiController {
|
||||
result.put("Server","");
|
||||
result.put("SIPSerial", sipConfig.getId());
|
||||
result.put("SIPRealm", sipConfig.getDomain());
|
||||
result.put("SIPHost", sipConfig.getIp());
|
||||
result.put("SIPHost", sipConfig.getShowIp());
|
||||
result.put("SIPPort", sipConfig.getPort());
|
||||
result.put("ChannelCount","1000");
|
||||
result.put("VersionType","");
|
||||
|
||||
Reference in New Issue
Block a user