Skip to content

Commit a1a0e7b

Browse files
committed
demo: add docker nginx demo
1 parent 2dc15a0 commit a1a0e7b

File tree

5 files changed

+371
-0
lines changed

5 files changed

+371
-0
lines changed

demos/with-docker-nginx/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 部署
2+
3+
```bash
4+
## 部署到docker的nginx容器中
5+
## http://localhost:8000
6+
docker-compose up -d
7+
```
8+
9+
## 访问
10+
11+
http://localhost:8000
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3'
2+
services:
3+
# 服务名称
4+
nginx:
5+
# 镜像:版本
6+
image: nginx:latest
7+
8+
# 指定容器名称
9+
container_name: ezuikit-nginx
10+
11+
# 映射容器8000端口到本地8000端口
12+
ports:
13+
- '8000:8000'
14+
15+
# 数据卷 映射本地文件到容器
16+
volumes:
17+
# 映射nginx.conf文件到容器的/etc/nginx/conf.d目录并覆盖default.conf文件
18+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
19+
# 映射dist文件夹到容器的/usr/share/nginx/html文件夹
20+
- ./html:/usr/share/nginx/html
21+
# 覆盖容器启动后默认执行的命令。
22+
23+
command: /bin/bash -c "nginx -g 'daemon off;'"

demos/with-docker-nginx/html/ezuikit.js

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
8+
/>
9+
<title>Document</title>
10+
<style>
11+
#video-container {
12+
/* width: 600px; */
13+
height: 400px;
14+
background-color: #000;
15+
}
16+
</style>
17+
<script src="./ezuikit.js"></script>
18+
</head>
19+
20+
<body>
21+
<div className="demo">
22+
<h2>视频模式使用示例:</h2>
23+
<div>
24+
<div id="video-container"></div>
25+
</div>
26+
<div>
27+
<button class="init">出初始化(init)</button>
28+
<button class="play">play</button>
29+
<button class="stop">stop</button>
30+
<button class="getOSDTime">getOSDTime</button>
31+
<button class="capturePicture">capturePicture</button>
32+
<button class="openSound">openSound</button>
33+
<button class="closeSound">closeSound</button>
34+
<button class="startSave">startSave</button>
35+
<button class="stopSave">stopSave</button>
36+
<button class="startTalk">开始对讲</button>
37+
<button class="stopTalk">结束对讲</button>
38+
<button class="fullscreen">全屏</button>
39+
<button class="destroy">销毁</button>
40+
</div>
41+
</div>
42+
<script>
43+
(function () {
44+
var player = null;
45+
46+
function destroy() {
47+
if (player) {
48+
player.destroy();
49+
}
50+
player = null;
51+
}
52+
53+
document.querySelector(".init").addEventListener("click", () => {
54+
if (player) {
55+
destroy();
56+
}
57+
58+
// fetch('https://open.ys7.com/jssdk/ezopen/demo/token')
59+
// .then(response => response.json())
60+
// .then(res => {
61+
// var accessToken = res.data.accessToken;
62+
player = new EZUIKit.EZUIKitPlayer({
63+
id: "video-container", // 视频容器ID
64+
accessToken:
65+
"at.9uoaxo0k3e5dinq8bretm18e5l37k1l6-26lx1qcvcc-1neesaz-kh9hqvqc3",
66+
url: "ezopen://open.ys7.com/BC7799091/1.hd.live",
67+
template: "pcLive", // simple: 极简版; pcLive: 预览; pcRec: 回放; security: 安防版; voice: 语音版;
68+
// width: 600, // 8.2.0 版本开始支持 style 里面宽的值(如 "100%" 或 '100vw' 或 "600px" 或 600 或 "1em" 等等)
69+
height: 400,
70+
language: "en", // zh | en
71+
// debugDownloadData: true, // 调试下载原始数据
72+
handleError: (error) => {
73+
console.error("handleError", error);
74+
},
75+
scaleMode: 1, // 默认 0 完全填充窗口,会有拉伸 1: 等比适配 2: 等比完全填充窗口, 超出隐藏 @sine 8.2.0
76+
env: {
77+
// https://open.ys7.com/help/1772?h=domain
78+
// domain默认是 https://open.ys7.com, 如果是私有化部署或海外的环境,请配置对应的domain
79+
// The default domain is https://open.ys7.com If it is a private deployment or overseas (outside of China) environment, please configure the corresponding domain
80+
domain: "https://open.ys7.com",
81+
},
82+
// 日志打印设置
83+
loggerOptions: {
84+
// player.setLoggerOptions(options)
85+
level: "INFO", // INFO LOG WARN ERROR
86+
name: "ezuikit",
87+
showTime: true,
88+
},
89+
// 视频流的信息回调类型
90+
/**
91+
* 打开流信息回调,监听 streamInfoCB 事件
92+
* 0 : 每次都回调
93+
* 1 : 只回调一次
94+
* 注意:会影响性能
95+
* 默认值 1
96+
*/
97+
streamInfoCBType: 1,
98+
// staticPath: "/ezuikit_static", // 如果想使用本地静态资源,请复制根目录下ezuikit_static 到当前目录下, 然后设置该值
99+
// v8.1.10
100+
// 自定义清晰度 默认 null, 如果有值 sdk 内部不在进行获取, null 默认使用接口获取的清晰度列表, videoLevelList.length === 0 不展示清晰度控件 sdk 内部不在进行获取, videoLevelList.length > 0 展示控件 sdk 内部不在进行获取
101+
// videoLevelList: [
102+
// { level: 0, name: "标清", streamTypeIn: 2 }, // 需要设备支持子码流
103+
// { level: 1, name: "高清", streamTypeIn: 1 },
104+
// ],
105+
// videoLevelList: [
106+
// { level: -1, name: "标清", streamTypeIn: 2 }, // 8.1.17 开始 当 level 的值小于 0时, 不在向设备发送指令,仅根据 streamTypeIn 切换码流 (请保证 streamTypeIn 对应的码流存在)
107+
// { level: -2, name: "高清", streamTypeIn: 1 }, // 8.1.17 开始 当 level 的值小于 0时, 不在向设备发送指令,仅根据 streamTypeIn 切换码流 (请保证 streamTypeIn 对应的码流存在)
108+
// ]
109+
});
110+
111+
// 8.1.x 版本, 9.x.x 移除了 eventEmitter
112+
// player.eventEmitter.on(EZUIKit.EZUIKitPlayer.EVENTS.videoInfo, (info) => {
113+
// console.log("eventEmitter videoInfo", info);
114+
// });
115+
// 8.2.0 开始 推荐使用 player.on
116+
// prettier-ignore
117+
player.on(EZUIKit.EZUIKitPlayer.EVENTS.videoInfo,(info) => {
118+
console.log("videoInfo", info);
119+
});
120+
121+
// 8.1.x 版本, 9.x.x 移除了 eventEmitter
122+
// player.eventEmitter.on(EZUIKit.EZUIKitPlayer.EVENTS.audioInfo, (info) => {
123+
// console.log("eventEmitter audioInfo", info);
124+
// });
125+
// 8.2.0 开始 推荐使用 player.on
126+
// prettier-ignore
127+
player.on(EZUIKit.EZUIKitPlayer.EVENTS.audioInfo, (info) => {
128+
console.log("audioInfo", info);
129+
});
130+
131+
// 首帧渲染成功
132+
// first frame display
133+
// 8.1.x 版本, 9.x.x 移除了 eventEmitter
134+
// player.eventEmitter.on(EZUIKit.EZUIKitPlayer.EVENTS.firstFrameDisplay, () => {
135+
// console.log("eventEmitter firstFrameDisplay ");
136+
// });
137+
// 8.2.0 开始 推荐使用 player.on
138+
// prettier-ignore
139+
player.on(EZUIKit.EZUIKitPlayer.EVENTS.firstFrameDisplay, () => {
140+
console.log("firstFrameDisplay ");
141+
});
142+
143+
// 8.1.x 版本, 9.x.x 移除了 eventEmitter
144+
// player.eventEmitter.on(EZUIKit.EZUIKitPlayer.EVENTS.streamInfoCB, (info) => {
145+
// console.log("eventEmitter streamInfoCB ", info);
146+
// });
147+
// 8.2.0 开始 推荐使用 player.on
148+
// prettier-ignore
149+
player.on(EZUIKit.EZUIKitPlayer.EVENTS.streamInfoCB, (info) => {
150+
console.log("streamInfoCB ", info);
151+
});
152+
});
153+
154+
document.querySelector(".fullscreen").addEventListener("click", () => {
155+
player.fullscreen();
156+
});
157+
158+
document.querySelector(".play").addEventListener("click", () => {
159+
var playPromise = player.play();
160+
playPromise.then((data) => {
161+
console.log("play", data);
162+
});
163+
});
164+
165+
document.querySelector(".stop").addEventListener("click", () => {
166+
var stopPromise = player.stop();
167+
stopPromise.then((data) => {
168+
console.log("stop", data);
169+
});
170+
});
171+
172+
document.querySelector(".getOSDTime").addEventListener("click", () => {
173+
var getOSDTimePromise = player.getOSDTime();
174+
getOSDTimePromise.then((data) => {
175+
console.log("getOSDTime: ", data);
176+
});
177+
});
178+
document
179+
.querySelector(".capturePicture")
180+
.addEventListener("click", () => {
181+
var capturePicturePromise = player.capturePicture();
182+
capturePicturePromise.then((data) => {
183+
console.log("promise 获取 数据", data);
184+
});
185+
});
186+
187+
document.querySelector(".openSound").addEventListener("click", () => {
188+
var openSoundPromise = player.openSound();
189+
openSoundPromise.then((data) => {
190+
console.log("promise 获取 数据", data);
191+
});
192+
});
193+
194+
document.querySelector(".closeSound").addEventListener("click", () => {
195+
var closeSoundPromise = player.closeSound();
196+
closeSoundPromise.then((data) => {
197+
console.log("promise 获取 数据", data);
198+
});
199+
});
200+
document.querySelector(".startSave").addEventListener("click", () => {
201+
var startSavePromise = player.startSave(`${new Date().getTime()}`);
202+
startSavePromise.then((data) => {
203+
console.log("promise 获取 数据", data);
204+
});
205+
});
206+
document.querySelector(".stopSave").addEventListener("click", () => {
207+
var stopSavePromise = player.stopSave();
208+
stopSavePromise.then((data) => {
209+
console.log("promise 获取 数据", data);
210+
});
211+
});
212+
document.querySelector(".startTalk").addEventListener("click", () => {
213+
player.startTalk();
214+
});
215+
document.querySelector(".stopTalk").addEventListener("click", () => {
216+
player.stopTalk();
217+
});
218+
document.querySelector(".destroy").addEventListener("click", destroy);
219+
})();
220+
</script>
221+
</body>
222+
</html>

demos/with-docker-nginx/nginx.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# gzip设置
2+
gzip on;
3+
gzip_vary on;
4+
5+
gzip_comp_level 6;
6+
gzip_buffers 16 8k;
7+
8+
gzip_min_length 1000;
9+
gzip_proxied any;
10+
gzip_disable "msie6";
11+
#gzip_http_version 1.0;
12+
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/wasm;
13+
14+
server {
15+
listen 8000;
16+
server_name localhost;
17+
18+
#charset koi8-r;
19+
#access_log /var/log/nginx/host.access.log main;
20+
21+
location / {
22+
add_header Access-Control-Allow-Origin * always;
23+
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
24+
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
25+
26+
root /usr/share/nginx/html;
27+
index index.html index.htm;
28+
# 其作用是按顺序检查文件是否存在,返回第一个找到的文件或文件夹(结尾加斜线表示为文件夹),如果所有的文件或文件夹都找不到,会进行一个内部重定向到最后一个参数。
29+
try_files $uri /index.html;
30+
}
31+
32+
#error_page 404 /404.html;
33+
34+
# redirect server error pages to the static page /50x.html
35+
#
36+
error_page 500 502 503 504 /50x.html;
37+
location = /50x.html {
38+
root /usr/share/nginx/html;
39+
}
40+
}
41+
42+
43+
44+

0 commit comments

Comments
 (0)