清理垃圾代码

This commit is contained in:
fsy
2025-03-22 21:12:27 +08:00
parent 91eb775713
commit 50336be317
3 changed files with 7 additions and 44 deletions

View File

@@ -157,9 +157,8 @@ class AgoraService {
try {
// Join the channel
this.uid = await this.client.join(this.appid, this.channel, this.token, uid);
this.isJoined = true;
// Enable volume indicator
this.client.enableAudioVolumeIndicator();
@@ -183,16 +182,13 @@ class AgoraService {
bitrate: 128 // 比特率
}
});
// 禁用本地音频监听,防止在耳机中听到自己的声音
this.localAudioTrack.play = function() {
console.log("Local audio playback disabled");
return;
};
// Publish local audio track
console.log("this.localAudioTrack:",this.localAudioTrack);
await this.client.publish([this.localAudioTrack]);
return true;
}catch(error){

View File

@@ -2,13 +2,12 @@ import axios from 'axios';
class ApiService {
constructor() {
this.baseUrl = '/create-api'; // Using Vite proxy instead of direct URL
this.baseUrl = '/create-api';
this.projectId = '01a1debc964a4c6a8df1de2a6ce7aa4d';
this.authToken = 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg='; // Set the auth token
this.client = axios.create({
headers: {
'Content-Type': 'application/json',
'Authorization': this.authToken
'Authorization': 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg=',
},
withCredentials: true
});
@@ -16,21 +15,9 @@ class ApiService {
setAgentId(agentId) {
this.agentId = agentId;
}
/**
* Set the authentication token
* @param {string} token - The authentication token
*/
setAuthToken(token) {
this.authToken = token;
this.client.defaults.headers.common['Authorization'] = token;
}
/**
* Join a project to start a conversation
* @param {string} channelName - The channel name
* @param {string} agentRtcUid - The agent RTC UID
* @returns {Promise} - The response from the API
*/
async joinProject(channelName = 'convaiconsole_122624', agentRtcUid = '29501') {
try {
@@ -111,17 +98,14 @@ class ApiService {
/**
* End the current session
* @returns {Promise} - The response from the API
*/
async endSession() {
console.log("this.agentId:",this.agentId);
try {
const response = await this.client.post(
`${this.baseUrl}/projects/${this.projectId}/agents/${this.agentId}/leave`
);
return response.data;
return response;
} catch (error) {
console.error('Error ending session:', error);
throw error;

View File

@@ -12,7 +12,6 @@ export const useChatStore = defineStore('chat', {
currentTranscript: '',
error: null,
audioLevel: 0,
authToken: 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg=', // Actual auth token
inConversation: false, // 是否在对话状态中
}),
@@ -23,23 +22,12 @@ export const useChatStore = defineStore('chat', {
},
actions: {
/**
* Initialize the chat
*/
async initialize() {
try {
// Set the auth token
apiService.setAuthToken(this.authToken);
// Initialize Agora service
agoraService.init();
// Join the project
const response = await apiService.joinProject();
console.log('res:',response);
// Join the Agora channel
const agent_id = response.agent_id;
const create_ts =response.create_ts;
const status =response.status;
@@ -89,16 +77,11 @@ export const useChatStore = defineStore('chat', {
if (!agoraService.localAudioTrack) {
agoraService.startAudioPublishing();
}
// 监听语音事件
// this.setupSpeechEventListeners();
return true;
},
/**
* 处理可读文本
* @param {string} text - 从Agora获取的可读文本
*/
handleReadableText(text) {
if (!text || !text.trim()) return;
@@ -115,7 +98,7 @@ export const useChatStore = defineStore('chat', {
const timeDiff = currentTime - new Date(lastMessage.timestamp);
// 如果时间差小于3秒更新最后一条消息
if (timeDiff < 3000) {
if (timeDiff < 5000) {
// 更新最后一条消息的内容
lastMessage.content = text;
// 更新时间戳