multiple-police-situations/public/cw_/index.html

193 lines
5.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0" />
<title>CMS Player</title>
<link rel="shortcut icon" href="#" />
<script src="./public/player/cmsplayer.js"></script>
<script src="./public/player/common.js"></script>
<script src="./public/player/pcm-player.js"></script>
<script src="./public/player/webgl.js"></script>
<script src="./public/player/cmstalk.js"></script>
<script src="./public/player/alawmulaw.js"></script>
<script src="./public/player/recorder-core.js"></script>
<script src="./public/js/moment.js"></script>
<script src="./public/js/axios.min.js"></script>
<script src="./public/js/jquery-2.2.3.min.js"></script>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
/* padding: 30px; */
box-sizing: border-box;
}
div {
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-html-user-select: none;
-webkit-user-select: none;
}
ul {
list-style: none;
}
ul li {
height: 100%;
float: left;
box-sizing: border-box;
}
#videoTimeTrack li {
border-right: 1px solid #ccc;
}
#videoTimeTrack li:first-child {
border-left: 1px solid #ccc;
}
#playerBox {
height: 96%;
width: 100%;
}
</style>
</head>
<body ontouchstart>
<div id="playerBox"></div>
<div>
<button class="layui-btn" id="talk-real-server">实时视频对讲(请配置URL)</button>
<!-- <input type="text" id="talkUrl" style="width: 600px" value="" /> -->
</div>
<script type="text/javascript">
window.onload = function () {
self.player = new Player($("#playerBox"));
function getParams(key) {
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]); // 使用 decodeURIComponent 代替 unescape
}
return null;
}
var locationUrl = window.location.href;
var id = getParams("id");
var title = getParams("title");
let requestBody = {
pointId: id,
useTLS: 0
}
// console.log(window.location, locationUrl, id, title);
try {
if (window.location.host === 'www.hndyjqrh.cn') {
requestBody.useTLS = 1
}
// requestBody.useTLS = 1
let url = 'https://www.hndyjqrh.cn/api/multialarm/video/preview'
axios({
method: 'post',
url,
data: { ...requestBody }
}).then(res => {
// console.log(res);
var PLAYURL = res.data.data.videoUrl
self.player.play(PLAYURL, true, "");
}).catch(function (error) {
console.log(error)
})
} catch (error) {
console.log(error);
}
$("html>head>title").html(title);
var wsUrl = ''
document.getElementById("talk-real-server").onclick = function () {
console.log(1111);
axios({
method: 'post',
url: 'https://www.hndyjqrh.cn/api/multialarm/talk/channel',
data: { ...requestBody }
}).then(res => {
console.log('talk/channel', res);
wsUrl = res.data.data.videoUrl
}).catch(function (error) {
console.log(error)
})
if (wsUrl.length > 0) {
// 创建 WebSocket 连接
const socket = new WebSocket(wsUrl);
// 监听 WebSocket 连接的打开事件
socket.onopen = function (event) {
console.log('WebSocket 连接已打开');
// 获取麦克风的音频流
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
// 使用 AudioContext 处理音频数据
const audioContext = new AudioContext();
const source = audioContext.createMediaStreamSource(stream);
const processor = audioContext.createScriptProcessor(4096, 1, 1);
// 监听音频数据
processor.onaudioprocess = function (event) {
const audioData = event.inputBuffer.getChannelData(0);
const float32Array = new Float32Array(audioData);
// 将浮点音频数据转换为 16 位 PCM 格式
const int16Array = new Int16Array(float32Array.length);
for (let i = 0; i < float32Array.length; i++) {
int16Array[i] = float32Array[i] * 0x7FFF; // 将 [-1, 1] 映射到 [-32768, 32767]
}
// 发送音频数据
socket.send(int16Array.buffer);
console.log('音频数据已发送');
};
// 将音频流连接到处理器并开始处理
source.connect(processor);
processor.connect(audioContext.destination);
})
.catch(error => {
console.error('获取音频流失败:', error);
});
};
// 监听 WebSocket 收到消息事件
socket.onmessage = function (event) {
console.log('收到消息:', event.data);
};
// 监听 WebSocket 连接关闭事件
socket.onclose = function (event) {
console.log('WebSocket 连接已关闭');
};
// 监听 WebSocket 连接出错事件
socket.onerror = function (event) {
console.error('WebSocket 错误:', event);
};
}
// var playUrl = document.getElementById("realplayUrl").value;
// var talkUrl = document.getElementById("talkUrl").value;
// self.player.talkUrl = talkUrl;
// self.player.play(playUrl, true, "");
}
}
</script>
</body>
</html>