648540858
4 years ago
32 changed files with 240 additions and 223 deletions
@ -1,43 +0,0 @@ |
|||
package com.genersoft.iot.vmp.media.zlm; |
|||
|
|||
import com.google.common.collect.ImmutableMap; |
|||
import org.mitre.dsmiley.httpproxy.ProxyServlet; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.boot.web.servlet.ServletRegistrationBean; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import javax.servlet.Servlet; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 对查询流媒体信息的请求进行反向代理 |
|||
*/ |
|||
@Configuration |
|||
public class SolrProxyServletConfiguration { |
|||
|
|||
// 读取配置文件中路由设置
|
|||
@Value("${proxy.servlet_url}") |
|||
private String servlet_url; |
|||
// 读取配置中代理目标地址
|
|||
@Value("${proxy.target_url}") |
|||
private String target_url; |
|||
|
|||
|
|||
|
|||
@Bean |
|||
public Servlet createProxyServlet(){ |
|||
// 创建新的ProxyServlet
|
|||
return new ProxyServlet(); |
|||
} |
|||
@Bean |
|||
public ServletRegistrationBean proxyServletRegistration(){ |
|||
ServletRegistrationBean registrationBean = new ServletRegistrationBean(createProxyServlet(), servlet_url); |
|||
//设置网址以及参数
|
|||
Map<String, String> params = ImmutableMap.of( |
|||
"targetUri", target_url, |
|||
"log", "true"); |
|||
registrationBean.setInitParameters(params); |
|||
return registrationBean; |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
package com.genersoft.iot.vmp.media.zlm; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
|||
import org.apache.http.HttpResponse; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.HttpRequest; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.client.HttpClientErrorException; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.Enumeration; |
|||
|
|||
@RestController |
|||
@RequestMapping("/zlm") |
|||
public class ZLMHTTPProxyController { |
|||
|
|||
|
|||
private final static Logger logger = LoggerFactory.getLogger(ZLMHTTPProxyController.class); |
|||
|
|||
@Autowired |
|||
private IVideoManagerStorager storager; |
|||
|
|||
|
|||
@ResponseBody |
|||
@RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8") |
|||
public Object proxy(HttpServletRequest request, HttpServletResponse response){ |
|||
|
|||
if (storager.getMediaInfo() == null) { |
|||
return "未接入流媒体"; |
|||
} |
|||
String requestURI = String.format("http://%s:%s%s?%s&%s", |
|||
storager.getMediaInfo().getLocalIP(), |
|||
storager.getMediaInfo().getHttpPort(), |
|||
request.getRequestURI().replace("/zlm",""), |
|||
storager.getMediaInfo().getHookAdminParams(), |
|||
request.getQueryString() |
|||
); |
|||
// 发送请求
|
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
//将指定的url返回的参数自动封装到自定义好的对应类对象中
|
|||
Object result = null; |
|||
try { |
|||
result = restTemplate.getForObject(requestURI,Object.class); |
|||
|
|||
}catch (HttpClientErrorException httpClientErrorException) { |
|||
response.setStatus(httpClientErrorException.getStatusCode().value()); |
|||
} |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
package com.genersoft.iot.vmp.utils; |
|||
|
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.net.InetAddress; |
|||
import java.net.UnknownHostException; |
|||
|
|||
public class IpUtil { |
|||
public static String getIpAddr(HttpServletRequest request) { |
|||
String ipAddress = null; |
|||
try { |
|||
ipAddress = request.getHeader("x-forwarded-for"); |
|||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
|||
ipAddress = request.getHeader("Proxy-Client-IP"); |
|||
} |
|||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
|||
ipAddress = request.getHeader("WL-Proxy-Client-IP"); |
|||
} |
|||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
|||
ipAddress = request.getRemoteAddr(); |
|||
if (ipAddress.equals("127.0.0.1")) { |
|||
// 根据网卡取本机配置的IP
|
|||
InetAddress inet = null; |
|||
try { |
|||
inet = InetAddress.getLocalHost(); |
|||
} catch (UnknownHostException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
ipAddress = inet.getHostAddress(); |
|||
} |
|||
} |
|||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
|||
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
|
|||
// = 15
|
|||
if (ipAddress.indexOf(",") > 0) { |
|||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
ipAddress=""; |
|||
} |
|||
// ipAddress = this.getRequest().getRemoteAddr();
|
|||
|
|||
return ipAddress; |
|||
} |
|||
} |
|||
|
|||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,4 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<cross-domain-policy> |
|||
<allow-access-from domain="*"/> |
|||
</cross-domain-policy> |
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@ |
|||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>default</title><script src=./dist/liveplayer-lib.min.js></script><link href=/css/app.ea73b2a1.css rel=preload as=style><link href=/css/chunk-vendors.b5921ce8.css rel=preload as=style><link href=/js/app.d31a42f9.js rel=preload as=script><link href=/js/chunk-vendors.21c802f5.js rel=preload as=script><link href=/css/chunk-vendors.b5921ce8.css rel=stylesheet><link href=/css/app.ea73b2a1.css rel=stylesheet></head><body><noscript><strong>We're sorry but default doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.21c802f5.js></script><script src=/js/app.d31a42f9.js></script></body></html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,4 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<cross-domain-policy> |
|||
<allow-access-from domain="*"/> |
|||
</cross-domain-policy> |
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -1,63 +0,0 @@ |
|||
<!DOCTYPE HTML> |
|||
<html> |
|||
<head> |
|||
<title>liveplayer</title> |
|||
<meta charset="utf-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
|||
<meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport"> |
|||
<script type="text/javascript" src="liveplayer-element.min.js"></script> |
|||
<script type="text/javascript"> |
|||
window.onload = function() { |
|||
|
|||
} |
|||
|
|||
window.addEventListener("message", function(event) { |
|||
var data = event.data; |
|||
switch (data.cmd) { |
|||
case 'switchUrl': |
|||
// 处理业务逻辑 |
|||
console.log("收到消息:"+JSON.stringify(data.params)); |
|||
var player = document.getElementById('player01'); |
|||
player.setAttribute("video-url",data.params["path"]); |
|||
break; |
|||
} |
|||
}); |
|||
|
|||
function getQueryVariable(variable) { |
|||
var query = window.location.search.substring(1); |
|||
var vars = query.split("&"); |
|||
for (var i = 0; i < vars.length; i++) { |
|||
var pair = vars[i].split("="); |
|||
if (pair[0] == variable) { |
|||
return pair[1]; |
|||
} |
|||
} |
|||
return (false); |
|||
} |
|||
|
|||
function onError(event){ |
|||
console.log("播放器错误:"+JSON.stringify(event)); |
|||
} |
|||
|
|||
function sendMsgToParent(cmd,data){ |
|||
window.parent.postMessage({ |
|||
cmd: cmd, |
|||
params: { |
|||
success: true, |
|||
data: data |
|||
} |
|||
}, '*'); |
|||
} |
|||
</script> |
|||
</head> |
|||
<body> |
|||
<live-player id="player01" live="true" stretch="true" show-custom-button="false" autoplay error="onError"> |
|||
</live-player> |
|||
<script> |
|||
var videoPath = getQueryVariable("url"); |
|||
console.log('播放地址:' + videoPath); |
|||
var player = document.getElementById('player01'); |
|||
player.setAttribute("video-url", videoPath); |
|||
</script> |
|||
</body> |
|||
</html> |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Loading…
Reference in new issue