Commit 78fac69cd569ede0ba5bf900f0df4f65c9229400
1 parent
d202291a
支持sdp ip 配置为域名
Showing
1 changed file
with
23 additions
and
1 deletions
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
| @@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Value; | @@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Value; | ||
| 6 | import org.springframework.context.annotation.Configuration; | 6 | import org.springframework.context.annotation.Configuration; |
| 7 | import org.springframework.util.StringUtils; | 7 | import org.springframework.util.StringUtils; |
| 8 | 8 | ||
| 9 | +import java.net.InetAddress; | ||
| 10 | +import java.net.UnknownHostException; | ||
| 11 | +import java.util.regex.Pattern; | ||
| 12 | + | ||
| 9 | 13 | ||
| 10 | @Configuration("mediaConfig") | 14 | @Configuration("mediaConfig") |
| 11 | public class MediaConfig{ | 15 | public class MediaConfig{ |
| @@ -161,7 +165,18 @@ public class MediaConfig{ | @@ -161,7 +165,18 @@ public class MediaConfig{ | ||
| 161 | if (StringUtils.isEmpty(sdpIp)){ | 165 | if (StringUtils.isEmpty(sdpIp)){ |
| 162 | return ip; | 166 | return ip; |
| 163 | }else { | 167 | }else { |
| 164 | - return sdpIp; | 168 | + if (isValidIPAddress(sdpIp)) { |
| 169 | + return sdpIp; | ||
| 170 | + }else { | ||
| 171 | + // 按照域名解析 | ||
| 172 | + String hostAddress = null; | ||
| 173 | + try { | ||
| 174 | + hostAddress = InetAddress.getByName(sdpIp).getHostAddress(); | ||
| 175 | + } catch (UnknownHostException e) { | ||
| 176 | + throw new RuntimeException(e); | ||
| 177 | + } | ||
| 178 | + return hostAddress; | ||
| 179 | + } | ||
| 165 | } | 180 | } |
| 166 | } | 181 | } |
| 167 | 182 | ||
| @@ -211,4 +226,11 @@ public class MediaConfig{ | @@ -211,4 +226,11 @@ public class MediaConfig{ | ||
| 211 | return mediaServerItem; | 226 | return mediaServerItem; |
| 212 | } | 227 | } |
| 213 | 228 | ||
| 229 | + private boolean isValidIPAddress(String ipAddress) { | ||
| 230 | + if ((ipAddress != null) && (!ipAddress.isEmpty())) { | ||
| 231 | + 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); | ||
| 232 | + } | ||
| 233 | + return false; | ||
| 234 | + } | ||
| 235 | + | ||
| 214 | } | 236 | } |