AudioHTML/js/equalizer.js

70 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

$(function () {
//判断浏览器是否支持WebSocket
var supportsWebSockets = 'WebSocket' in window || 'MozWebSocket' in window;
if (supportsWebSockets) {
//建立WebSocket连接ip地址换成自己主机ip
// var ws = new WebSocket("wss://fat-hk-ws-sdk.szfiu.com/websocket");
var ws = new WebSocket("ws://192.168.0.116:13500");
ws.onopen = function () {
//当WebSocket创建成功时触发onopen事件
// console.log("websocket连接成功");
// //ws.send("hello"); //将消息发送到服务端
// ws.send(
// JSON.stringify({
// symbols: "['00700.hk]",
// command: 0,
// version: '1.0.0',
// token: 'szfiu',
// heartBeat: 'heartBeat'
// })
// );
}
ws.onmessage = function (e) {
//当客户端收到服务端发来的消息时触发onmessage事件参数e.data包含server传递过来的数据
// console.log("收到数据");
// console.log(e.data);
// console.log(typeof (e.data))
var eqData = $.parseJSON(e.data).content
let number = eqData.value
if (eqData.value < -72) {
number = -72
}
if (eqData.value > 0) {
number = 0
}
// console.log(number)
if (eqData.module == "linein_L") {
LineInputLeftRandomBar(number)
}
else if (eqData.module == "linein_R") {
LineInputRightRandomBar(number)
}
else if (eqData.module == "output_L") {
OutputVolumeLeftRandomBar(number);
}
else if (eqData.module == "output_R") {
OutputVolumeRightRandomBar(number);
}
else if (eqData.module == "mic1") {
Microphone1LeftRandomBar(number)
}
else {
Microphone2LeftRandomBar(number)
}
}
ws.onclose = function (e) {
//当客户端收到服务端发送的关闭连接请求时触发onclose事件
console.log("websocket已断开");
}
ws.onerror = function (e) {
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
console.log("websocket发生错误" + e);
}
} else {
layer.alert("您的浏览器不支持 WebSocket!");
}
});