2905325171@qq.com 6abfeacfb5 Initial commit
2024-02-06 17:36:01 +08:00

76 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>播放</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/style.css"/>
<script src="https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/index.js"></script>
<style>
.replayer-wrapper {
left: 0;
}
</style>
</head>
<body style="height: 100vh">
</body>
<script>
let replayer = null
// WebSocket构造函数创建WebSocket对象
let ws = new WebSocket('ws://localhost:8080/play')
// 连接成功后的回调函数
ws.onopen = function (params) {
console.log('客户端连接成功')
};
// 从服务器接受到信息时的回调函数
ws.onmessage = function (e) {
let events = JSON.parse(e.data).events
addEvents(events)
};
// 连接关闭后的回调函数
ws.onclose = function (evt) {
console.log("关闭客户端连接");
};
// 连接失败后的回调函数
ws.onerror = function (evt) {
console.log("连接失败了");
};
// 监听窗口关闭事件当窗口关闭时主动去关闭websocket连接防止连接还没断开就关闭窗口这样服务端会抛异常。
window.onbeforeunload = function () {
ws.close();
}
function addEvents(events) {
if (replayer == null) {
replayer = new rrwebPlayer({
target: document.body, // 可以自定义 DOM 元素
// 配置项
props: {
events: events,
height: '99vh',
UNSAFE_replayCanvas: true,
liveMode: true,
skipInactive: false,
autoPlay: true,
showController: false
},
});
replayer.play();
}
for (let i = 0; i < events.length; i++) {
console.log('添加事件:', events[i])
replayer.addEvent(events[i])
}
}
</script>
</html>