From 700985ca63deb37221b448c19c2d15f4129ffaee Mon Sep 17 00:00:00 2001 From: fsy Date: Wed, 19 Mar 2025 14:36:18 +0800 Subject: [PATCH] =?UTF-8?q?RTC=E9=A1=BA=E5=88=A9=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/agora.js | 16 +++++++++++----- src/stores/chat.js | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/services/agora.js b/src/services/agora.js index e07adb9..e6abdca 100644 --- a/src/services/agora.js +++ b/src/services/agora.js @@ -9,6 +9,9 @@ class AgoraService { this.remoteUsers = {}; this.volumeIndicator = null; this.vadEnabled = true; + this.appid = '01a1debc964a4c6a8df1de2a6ce7aa4d'; + this.token = '007eJxTYHi+XWtqBkPmn71LGvdmPds7sfiQfomBxpt3XMfOC53fcjVegcHAMNEwJTUp2dLMJNEk2SzRIiUNyDdKNEtONU9MNEkpibmZ3hDIyPDYXo2JkQECQXwRhuT8vLLETCBZnJ+TGm9oYmluYMDAAACcPigI'; + this.channel = 'convaiconsole_149700'; this.vadParams = { interruptDurationMs: 160, prefixPaddingMs: 300, @@ -69,12 +72,13 @@ class AgoraService { * @param {string} channel - The channel name to join * @param {string} uid - The user ID (optional) */ - async join(token, channel, uid = null) { + async join(agent_id, create_ts, status, uid = null) { try { - this.uid = uid || `user_${Math.floor(Math.random() * 1000000)}`; - // Join the channel - await this.client.join(token, channel, this.uid); + this.uid = await this.client.join(this.appid, this.channel, this.token, uid); + + console.log("successful! this.uid is ", this.uid); + this.isJoined = true; // Create and publish local audio track @@ -94,7 +98,9 @@ class AgoraService { // Enable volume indicator this.client.enableAudioVolumeIndicator(); - + + console.log("status:", this.status); + return true; } catch (error) { console.error('Error joining channel:', error); diff --git a/src/stores/chat.js b/src/stores/chat.js index c4d6b0b..9cb9083 100644 --- a/src/stores/chat.js +++ b/src/stores/chat.js @@ -36,17 +36,24 @@ export const useChatStore = defineStore('chat', { // Join the project const response = await apiService.joinProject(); - // Join the Agora channel - const { token, channel } = response.properties; - const agentRtcUid = response.properties.agent_rtc_uid; + console.log('res:',response); - await agoraService.join(token, channel, agentRtcUid); + // Join the Agora channel + // const { token, channel } = response.properties; + // const agentRtcUid = response.properties.agent_rtc_uid; + const agent_id = response.agent_id; + const create_ts =response.create_ts; + const status =response.status; + + await agoraService.join(agent_id, create_ts, status) + // await agoraService.join(token, channel, agentRtcUid); this.isConnected = true; this.error = null; // Add greeting message - const greetingMessage = response.properties.llm.greeting_message; + // const greetingMessage = response.properties.llm.greeting_message; + const greetingMessage = "你好呀,有什么可以帮您?"; if (greetingMessage) { this.addMessage({ id: Date.now(),