Commit 15ab7cd6 by 李宁

1

1 parent 75d6ec4d
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
</div> </div>
</div> </div>
<!-- <audio id="mp3Source" muted playsinline src=""></audio> --> <audio id="mp3Source" muted playsinline src=""></audio>
<div class="alertDiv" id="accountAlertDiv"> <div class="alertDiv" id="accountAlertDiv">
<div class="inner"> <div class="inner">
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
<script src="js/util.js?1212"></script> <script src="js/util.js?1212"></script>
<script src="js/vue.min.js"></script> <script src="js/vue.min.js"></script>
<script src="js/vant.min.js"></script> <script src="js/vant.min.js"></script>
<script src="js/demo.js?1203334330"></script> <script src="js/demo.js?272721319"></script>
</body> </body>
</html> </html>
\ No newline at end of file \ No newline at end of file
...@@ -275,7 +275,7 @@ function getProcess(){ ...@@ -275,7 +275,7 @@ function getProcess(){
// $("#mp3Source")[0].play() // $("#mp3Source")[0].play()
// },350) // },350)
let buff = await loadPrompt(res.voiceUrlMp3); // 先解码 let buff = await loadPrompt(res.voiceUrlMp3);
playPrompt(buff); playPrompt(buff);
} }
audioSet(false) audioSet(false)
...@@ -383,7 +383,7 @@ function audioStart(){ ...@@ -383,7 +383,7 @@ function audioStart(){
} }
}) })
} }
function audioEnd(){ function audioEnd(ifEnd){
util.httpRequest({ util.httpRequest({
url: '/startOrEnd', url: '/startOrEnd',
data: { data: {
...@@ -394,7 +394,7 @@ function audioEnd(){ ...@@ -394,7 +394,7 @@ function audioEnd(){
} }
}) })
if(stepId.includes('end')){ if(ifEnd){
free() free()
window.location.replace('result.html?time='+ new Date().getTime()) window.location.replace('result.html?time='+ new Date().getTime())
...@@ -419,14 +419,13 @@ async function startWebAudioChain() { ...@@ -419,14 +419,13 @@ async function startWebAudioChain() {
/* 2. 加载「真实提示音」→ 音量压到 0.0001 → loop 永驻 */ /* 2. 加载「真实提示音」→ 音量压到 0.0001 → loop 永驻 */
// ① 先加载同一条提示音(已缓存 // ① 先加载同一条提示音(已缓存
const buf = await loadPrompt('https://zjaudio.eos-wuxi-5.cmecloud.cn/IqiVe4GU.mp3'); const buf = await loadPrompt('https://zjaudio.eos-wuxi-5.cmecloud.cn/IqiVe4GU.mp3');
// ② 创建 BufferSource
let shadowBufNode = mainCtx.createBufferSource(); let shadowBufNode = mainCtx.createBufferSource();
shadowBufNode.buffer = buf; shadowBufNode.buffer = buf;
shadowBufNode.loop = true; shadowBufNode.loop = true;
const shadowGain = mainCtx.createGain(); const shadowGain = mainCtx.createGain();
shadowGain.gain.value = 0.0001; // 用户听不见,但系统认为“有声音” shadowGain.gain.value = 0.0001;
shadowBufNode.connect(shadowGain).connect(mainCtx.destination); shadowBufNode.connect(shadowGain).connect(mainCtx.destination);
shadowBufNode.start(); // 永不 stop shadowBufNode.start();
/* 3. 送回 LiveKit */ /* 3. 送回 LiveKit */
const dest = mainCtx.createMediaStreamDestination(); const dest = mainCtx.createMediaStreamDestination();
...@@ -451,27 +450,32 @@ async function loadPrompt(url) { ...@@ -451,27 +450,32 @@ async function loadPrompt(url) {
return promptBuffer return promptBuffer
} }
let currentSource = null; let currentSource = null;
function playPrompt(buffer) { async function playPrompt(buffer) {
if (!mainCtx) return; if (!mainCtx) return;
// 1. 停掉上一条
if (currentSource) { if (currentSource) {
try { currentSource.stop(); } catch (e) { } try { currentSource.stop(); } catch {}
currentSource = null; currentSource = null;
setTimeout(()=>{
playPrompt(buffer)
},300)
return
} }
// 2. 创建新节点 // 2. 创建新节点
const src = mainCtx.createBufferSource(); currentSource = mainCtx.createBufferSource();
src.buffer = buffer; currentSource.buffer = buffer;
src.connect(mainCtx.destination); currentSource.connect(mainCtx.destination);
src.start(); currentSource.start(0);
audioStart() audioStart()
// 3. 记录引用
currentSource = src;
// 4. 播放完毕自动清空 // 4. 播放完毕自动清空
src.onended = () => { let ifEnd = stepId.includes('end')
currentSource.onended = () => {
currentSource = null; currentSource = null;
audioEnd() audioEnd(ifEnd)
}; };
} }
//---------音频播放新逻辑--------- //---------音频播放新逻辑---------
...@@ -1095,12 +1099,10 @@ async function setEnabled(type, state) { ...@@ -1095,12 +1099,10 @@ async function setEnabled(type, state) {
//声网的入会逻辑 //声网的入会逻辑
async function initSw(data){ async function initSw(data){
createClient() createClient()
options.channel = data.data.data.channel options.channel = data.data.data.channel
options.uid = data.data.data.uid options.uid = data.data.data.uid
options.token = data.data.data.token options.token = data.data.data.token
let flag = await join() let flag = await join()
if(!flag){ if(!flag){
$('#loading').hide() $('#loading').hide()
util.toast('加入频道失败') util.toast('加入频道失败')
...@@ -1111,7 +1113,7 @@ async function initSw(data){ ...@@ -1111,7 +1113,7 @@ async function initSw(data){
await createTrackAndPublish() await createTrackAndPublish()
} }
//livekit的入会逻辑 //livekit的入会逻辑
async function initLk(){ async function initLk(data){
// 创建房间实例,启用自适应流和动态发布 // 创建房间实例,启用自适应流和动态发布
room = new LivekitClient.Room({ room = new LivekitClient.Room({
adaptiveStream: true, adaptiveStream: true,
...@@ -1157,28 +1159,14 @@ var room = null ...@@ -1157,28 +1159,14 @@ var room = null
var rtcType = '' var rtcType = ''
var startZjFlag = true var startZjFlag = true
async function init(){ async function init(){
$('#loadingText').text('开启中,请稍候...')
$('#loading').show()
setTimeout(()=>{
if(startZjFlag){
$('#loading').hide()
$('#beginFail').show()
}
},20000)
snInputNum = window.snInputNum||5 snInputNum = window.snInputNum||5
noShootNum = window.noShootNum||3 noShootNum = window.noShootNum||3
accountInputNum = window.accountInputNum||5 accountInputNum = window.accountInputNum||5
// $("#mp3Source").attr('src', 'https://lgyztest.obs.cidc-rp-12.joint.cmecloud.cn/file/temp/2025-01-08/hhT2XXAj.mp3')
// $("#mp3Source")[0].autoplay = true
// $("#mp3Source")[0].play()
let data = await util.httpRequest({ let data = await util.httpRequest({
url: '/createRoom', url: '/createRoom',
data: { data: {
applyId: applyId, applyId: applyId
rtcType: '2'
} }
}) })
...@@ -1192,7 +1180,7 @@ async function init(){ ...@@ -1192,7 +1180,7 @@ async function init(){
sessionStorage.setItem('haCallId',callId) sessionStorage.setItem('haCallId',callId)
rtcType = data.data.data.rtcType rtcType = data.data.data.rtcType
if(data.data.data.rtcType == 1){ if(rtcType == 1){
await initSw(data) await initSw(data)
}else{ }else{
await initLk(data) await initLk(data)
...@@ -1269,9 +1257,18 @@ $('#videoBegin').click(async ()=>{ ...@@ -1269,9 +1257,18 @@ $('#videoBegin').click(async ()=>{
} }
$('#beginAlert').hide() $('#beginAlert').hide()
$('#loadingText').text('开启中,请稍候...')
$('#loading').show()
setTimeout(()=>{
if(startZjFlag){
$('#loading').hide()
$('#beginFail').show()
}
},20000)
mainCtx = new (window.AudioContext || window.webkitAudioContext)({ mainCtx = new (window.AudioContext || window.webkitAudioContext)({
latencyHint: 'interactive' latencyHint: 'interactive',
sinkId: 'default'
}); });
if (mainCtx.state === 'suspended') await mainCtx.resume(); if (mainCtx.state === 'suspended') await mainCtx.resume();
...@@ -1281,6 +1278,10 @@ $('#videoBegin').click(async ()=>{ ...@@ -1281,6 +1278,10 @@ $('#videoBegin').click(async ()=>{
await startWebAudioChain() await startWebAudioChain()
// $("#mp3Source").attr('src', 'https://lgyztest.obs.cidc-rp-12.joint.cmecloud.cn/file/temp/2025-01-08/hhT2XXAj.mp3')
// $("#mp3Source")[0].autoplay = true
// $("#mp3Source")[0].play()
init() init()
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!