yt-chat-components 1.6.3 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/YtChatView/chatWidget/chatWindow/audioPlayer/AudioPlayer.tsx +1 -1
- package/src/YtChatView/chatWidget/chatWindow/audioRecorder/index.tsx +1 -1
- package/src/YtChatView/chatWidget/chatWindow/callInterface/index.tsx +13 -6
- package/src/YtChatView/chatWidget/chatWindow/index.tsx +1 -1
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@ export class AudioPlayer {
|
|
|
24
24
|
// this.token = 'd20cf27fac634fee88d5d54a12cc36a6';
|
|
25
25
|
|
|
26
26
|
this.appkey = 'DhyCL7mwzachpGjL';
|
|
27
|
-
this.token = '
|
|
27
|
+
this.token = '980bc0c1a3fe4fa093ae7cbb470c086f';
|
|
28
28
|
|
|
29
29
|
this.taskId = uuidv4().replaceAll('-', '');
|
|
30
30
|
if (voice){
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import React, {useEffect, useRef, useState} from 'react';
|
|
2
3
|
import {Avatar, Button, message} from 'antd';
|
|
3
4
|
import './index.module.css';
|
|
@@ -63,7 +64,6 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
63
64
|
const vadProcessorRef = useRef<ScriptProcessorNode | null>(null);
|
|
64
65
|
const audioContextRef = useRef<AudioContext | null>(null);
|
|
65
66
|
const [isSpeakingNow,setIsSpeakingNow] = useState(false);
|
|
66
|
-
const audioPlayerInstance = new StreamAudioPlayer();
|
|
67
67
|
|
|
68
68
|
// 添加统一的WebSocket消息发送方法
|
|
69
69
|
const sendWebSocketMessage = (type: string, data: any) => {
|
|
@@ -123,13 +123,15 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
123
123
|
const handleAudioChunkData = async (audioData: string) => {
|
|
124
124
|
try {
|
|
125
125
|
// 添加音频片段到播放器
|
|
126
|
-
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
window.audioPlayerInstance.enqueueAudioChunk(audioData);
|
|
127
128
|
|
|
128
129
|
// 设置状态为“正在回复”
|
|
129
130
|
setWorkStatus('正在回复');
|
|
130
131
|
|
|
131
132
|
// 开始播放,并在所有音频完成后恢复状态
|
|
132
|
-
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
window.audioPlayerInstance.play(() => {
|
|
133
135
|
console.log("全部音频播放完成!");
|
|
134
136
|
setWorkStatus('正在聆听');
|
|
135
137
|
});
|
|
@@ -316,7 +318,8 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
316
318
|
msgId: msgIdRef.current,
|
|
317
319
|
});
|
|
318
320
|
// 暂停当前正在播放的内容
|
|
319
|
-
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
window.audioPlayerInstance.stop()
|
|
320
323
|
console.log('发送完毕');
|
|
321
324
|
|
|
322
325
|
// 添加用户消息到聊天记录
|
|
@@ -398,7 +401,8 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
398
401
|
console.log("user-audio-text")
|
|
399
402
|
console.log(message.textResponse)
|
|
400
403
|
// 清理当前正在回复的内容
|
|
401
|
-
|
|
404
|
+
// @ts-ignore
|
|
405
|
+
window.audioPlayerInstance.stop()
|
|
402
406
|
// 插入语音到聊天记录
|
|
403
407
|
addMessage({
|
|
404
408
|
messageItemList: [
|
|
@@ -499,6 +503,8 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
499
503
|
// 初始化WebRTC连接
|
|
500
504
|
useEffect(() => {
|
|
501
505
|
initWebRTC().then();
|
|
506
|
+
// @ts-ignore
|
|
507
|
+
window.audioPlayerInstance = new StreamAudioPlayer();
|
|
502
508
|
// 清理函数
|
|
503
509
|
return clear
|
|
504
510
|
}, []);
|
|
@@ -566,7 +572,8 @@ const CallInterface: React.FC<CallInterfaceProps> = ({
|
|
|
566
572
|
localStreamRef.current.getTracks().forEach(track => track.stop());
|
|
567
573
|
}
|
|
568
574
|
// 关闭音频播放
|
|
569
|
-
|
|
575
|
+
// @ts-ignore
|
|
576
|
+
window.audioPlayerInstance.destroy();
|
|
570
577
|
onHangup();
|
|
571
578
|
};
|
|
572
579
|
|
|
@@ -1237,7 +1237,7 @@ export default function ChatWindow({
|
|
|
1237
1237
|
}
|
|
1238
1238
|
|
|
1239
1239
|
const renderInputArea = () => {
|
|
1240
|
-
if (isShowMobileInputArea) renderInputAreaMobile();
|
|
1240
|
+
if (isShowMobileInputArea) return renderInputAreaMobile();
|
|
1241
1241
|
let isRender = messages.length === 0
|
|
1242
1242
|
if (messages.length > 0) {
|
|
1243
1243
|
const {messageItemList} = messages[messages.length - 1]
|