-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
318 lines (289 loc) · 9.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html style="background-color: #202124;">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<title>
彗酱今天也很可爱
</title>
<link rel="icon" href="icon.png" type="image/x-icon">
<link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.15.2/skins/default/aliplayer-min.css"
/>
<script type="text/javascript" charset="utf-8" src="https://g.alicdn.com/de/prismplayer/2.15.2/aliplayer-min.js">
</script>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<link rel="stylesheet" href="style.min.css"/>
<script src="CommentCoreLibrary.min.js">
</script>
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@4.4.1/dist/socket.io.min.js">
</script>
</head>
<style>
.prism-player {
margin: 0 auto;
max-width: 800px;
background-color: #202124;
}
#my-player {
border: none;
}
#danmaku_send {
display: flex;
align-items: center;
justify-content: center;
}
#send-danmaku-btn {
margin-right: 10px;
background-color: #8f4185;
color: white;
border-radius: 10px;
padding: 5px 10px;
border: none;
}
#send-danmaku-field {
width: 300px;
border: none;
padding: 5px;
border-radius: 10px;
}
a {
display: block;
text-align: center;
margin: 10px;
color: rgba(204, 204, 255, 0.98);
text-decoration: none;
}
.prism-ErrorMessage {
border-radius: 10px;
border-radius: 10px;
position: absolute;
left: 0px;
top: 0px;
display: block;
}
body {
margin: 0;
padding: 0;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
height: 100vh; /* 让背景铺满整个视口高度 */
}
</style>
<body>
<img src="icon.png" alt="logo" style="position: absolute; top: 0; left: 0; margin: 20px;height: 70px;">
<div class="prism-player" id="playercon" style="border-radius: 10px;">
<div id='my-player' class='abp' style="width: 100%; height: 500px;z-index:1;border-radius: 10px;">
<div id='my-comment-stage' class='container' style="width: 100%; height: 500px;z-index:1;border-radius: 10px;">
</div>
</div>
<div style="bottom:0;z-index:999;position:absolute" id="danmaku_send">
<button id="send-danmaku-btn">
发送弹幕
</button>
<input id="send-danmaku-field" placeholder="说,都可以说,有什么不能说的"/>
<label class="switch">
<input type="checkbox" id="toggleSwitch" checked onchange="toggleSocket()">
<span class="slider"></span>
</label>
<span class="switch-label" style="
text-align: center;
color: #ccccff;
text-decoration: none;">弹幕状态: <span id="status" style="
text-align: center;
color: #ccccff;
text-decoration: none;">打开</span></span>
</div>
</div>
<a id="contentLink"></a>
<a>
</a>
<a style="color:red;font-weight:bold;">
</a>
<br/>
<a>已知ipv6有卡顿现象,请避免在开启ipv6的情况下观看。部分校园网可能会劫持DNS阻碍访问,请打开安全DNS解决</a>
<script src="https://code.jquery.com/jquery-3.6.4.min.js">
</script>
<script>
//写入推流源
var myUrl;
// 获取 URL 中的参数
const urlParams = new URLSearchParams(window.location.search);
// 从 URL 中获取后端地址参数
const backendUrl = urlParams.get('backendUrl');
// 存储后端地址到变量中
if (backendUrl) {
// 如果参数存在,则将其存储到变量中
myUrl = backendUrl + "/live/homo";
} else {
alert("后端为空,请检查url参数是否完整");
}
const getUrlParam = function (name) {
let url = window.location.search.substr(1);
let reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
let result = url.match(reg);
return result ? decodeURIComponent(result[2]) : null;
}; // 保存 channel 参数值
const channel = getUrlParam('channel');
var player = new Aliplayer({
"id": "playercon",
"source": myUrl + channel + ".m3u8",
"width": "100%",
"height": "500px",
"autoplay": true,
"isLive": true,
"rePlay": false,
"playsinline": true,
"preload": true,
"enableStashBufferForFlv": true,
"stashInitialSizeForFlv": 32,
"controlBarVisibility": "hover",
"useH5Prism": true
}, function (player) {
console.log("The player is created");
});
var CM = new CommentManager(document.getElementById('my-comment-stage'));
CM.init(); // 初始化
// 基于 socket.io 和 JQuery来简化代码
let socket = io(backendUrl + ':2083/'); //开启流
var button = document.getElementById('send-danmaku-btn');
//开关控制弹幕
function toggleSocket() {
var toggleSwitch = document.getElementById('toggleSwitch');
var status = document.getElementById('status');
if (toggleSwitch.checked) {
// 打开连接
openSocket();
status.textContent = '打开';
} else {
// 关闭连接
closeSocket();
status.textContent = '关闭';
}
}
// 创建一个socket变量用于存储Socket.IO连接
// 打开连接
function openSocket() {
if (!socket) {
socket = io(backendUrl + ':2083/');
Socket();
button.disabled = false;
button.textContent = "发送弹幕"
console.log('Socket.IO连接已打开');
} else {
console.log('Socket.IO连接已经打开');
}
}
Socket();
// 关闭连接
function closeSocket() {
if (socket) {
socket.disconnect();
socket = null;
button.disabled = true;
button.textContent = "弹幕关闭"
console.log('Socket.IO连接已关闭');
} else {
button.disabled = true;
button.textContent = "弹幕关闭"
console.log('Socket.IO连接已经关闭');
}
}
function Socket() {
console.log(socket.id); // x8WIv7-mJelg7on_ALbx
socket.on('danmaku' + channel, (data) => {
// 当遇到 danmaku 事件,就把推送来的弹幕推送给 CCL
var danmaku = JSON.parse(data);
console.log(data);
if (danmaku.hasOwnProperty('stime')) {
// 弹幕有时间轴位置,那就插入时间轴
CM.insert(danmaku);
} else {
// 弹幕没有时间轴位置就立刻显示(不记录)
CM.send(danmaku);
}
CM.start();
});
}
//全屏时重新初始化弹幕位置
var fullscreenBtn = document.querySelector('.prism-fullscreen-btn');
fullscreenBtn.addEventListener('click', function () {
console.log("全屏");
setTimeout(function () {
CM = new CommentManager(document.getElementById('my-comment-stage'));
CM.init();
}, 500);
});
$('#send-danmaku-btn').click(function () {
//当按了发送弹幕的按钮
var data = {
"text": $('#send-danmaku-field').val(),
"stime": playercon.currentTime,
"mode": 1,
"size": 25,
"color": 0xFFFFFF,
"ch": channel
};// 通过UI获取新弹幕的信息
//包装并发射弹幕
socket.emit('danmaku', JSON.stringify(data));
//清除 UI 文字部分
$('#send-danmaku-field').val("");
});
socket.on("hello", (arg) => {
console.log(arg); // world
});
const element = document.getElementById("my-comment-stage");
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.webkitRequestFullscreen) { /* Safari */
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) { /* IE11 */
element.msRequestFullscreen();
}
//点击时显示发送弹幕10秒
$("#danmaku_send").hide();
var inputFocused = false;
$("#send-danmaku-field").focus(function () {
inputFocused = true;
});
$("#send-danmaku-field").blur(function () {
inputFocused = false;
setTimeout(function () {
if (!inputFocused) {
$("#danmaku_send").hide();
}
}, 10000);
});
$(document).click(function () {
if (!inputFocused) {
$("#danmaku_send").show();
setTimeout(function () {
if (!inputFocused) {
$("#danmaku_send").hide();
}
}, 10000);
}
});
</script>
<script type="text/javascript">
function fetchAndDisplayContent(url, elementId) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var fileContent = xhr.responseText;
var fullContent = "后端服务器信息:" + fileContent; // 添加前缀
var link = document.getElementById(elementId);
link.innerText = fullContent;
// link.href = "data:text/plain;charset=utf-8," + encodeURIComponent(fullContent);
}
};
xhr.send();
}
fetchAndDisplayContent(backendUrl + "/information.txt", "contentLink");
</script>
</body>