清理垃圾代码

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,7 +157,6 @@ class AgoraService {
try { try {
// Join the channel // Join the channel
this.uid = await this.client.join(this.appid, this.channel, this.token, uid); this.uid = await this.client.join(this.appid, this.channel, this.token, uid);
this.isJoined = true; this.isJoined = true;
// Enable volume indicator // Enable volume indicator
@@ -190,9 +189,6 @@ class AgoraService {
return; return;
}; };
// Publish local audio track
console.log("this.localAudioTrack:",this.localAudioTrack);
await this.client.publish([this.localAudioTrack]); await this.client.publish([this.localAudioTrack]);
return true; return true;
}catch(error){ }catch(error){

View File

@@ -2,13 +2,12 @@ import axios from 'axios';
class ApiService { class ApiService {
constructor() { constructor() {
this.baseUrl = '/create-api'; // Using Vite proxy instead of direct URL this.baseUrl = '/create-api';
this.projectId = '01a1debc964a4c6a8df1de2a6ce7aa4d'; this.projectId = '01a1debc964a4c6a8df1de2a6ce7aa4d';
this.authToken = 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg='; // Set the auth token
this.client = axios.create({ this.client = axios.create({
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': this.authToken 'Authorization': 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg=',
}, },
withCredentials: true withCredentials: true
}); });
@@ -17,20 +16,8 @@ class ApiService {
this.agentId = 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 * 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') { async joinProject(channelName = 'convaiconsole_122624', agentRtcUid = '29501') {
try { try {
@@ -111,17 +98,14 @@ class ApiService {
/** /**
* End the current session * End the current session
* @returns {Promise} - The response from the API
*/ */
async endSession() { async endSession() {
console.log("this.agentId:",this.agentId);
try { try {
const response = await this.client.post( const response = await this.client.post(
`${this.baseUrl}/projects/${this.projectId}/agents/${this.agentId}/leave` `${this.baseUrl}/projects/${this.projectId}/agents/${this.agentId}/leave`
); );
return response.data; return response;
} catch (error) { } catch (error) {
console.error('Error ending session:', error); console.error('Error ending session:', error);
throw error; throw error;

View File

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