支持sdp ip 配置为域名
This commit is contained in:
parent
d1c15ad520
commit
998b8323f3
@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
@Configuration("mediaConfig")
|
@Configuration("mediaConfig")
|
||||||
public class MediaConfig{
|
public class MediaConfig{
|
||||||
@ -161,7 +165,18 @@ public class MediaConfig{
|
|||||||
if (StringUtils.isEmpty(sdpIp)){
|
if (StringUtils.isEmpty(sdpIp)){
|
||||||
return ip;
|
return ip;
|
||||||
}else {
|
}else {
|
||||||
return sdpIp;
|
if (isValidIPAddress(sdpIp)) {
|
||||||
|
return sdpIp;
|
||||||
|
}else {
|
||||||
|
// 按照域名解析
|
||||||
|
String hostAddress = null;
|
||||||
|
try {
|
||||||
|
hostAddress = InetAddress.getByName(sdpIp).getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return hostAddress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,4 +226,11 @@ public class MediaConfig{
|
|||||||
return mediaServerItem;
|
return mediaServerItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidIPAddress(String ipAddress) {
|
||||||
|
if ((ipAddress != null) && (!ipAddress.isEmpty())) {
|
||||||
|
return Pattern.matches("^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$", ipAddress);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user