RTC顺利接入

This commit is contained in:
fsy
2025-03-19 14:36:18 +08:00
parent 375d94ab26
commit 700985ca63
2 changed files with 23 additions and 10 deletions

View File

@@ -9,6 +9,9 @@ class AgoraService {
this.remoteUsers = {}; this.remoteUsers = {};
this.volumeIndicator = null; this.volumeIndicator = null;
this.vadEnabled = true; this.vadEnabled = true;
this.appid = '01a1debc964a4c6a8df1de2a6ce7aa4d';
this.token = '007eJxTYHi+XWtqBkPmn71LGvdmPds7sfiQfomBxpt3XMfOC53fcjVegcHAMNEwJTUp2dLMJNEk2SzRIiUNyDdKNEtONU9MNEkpibmZ3hDIyPDYXo2JkQECQXwRhuT8vLLETCBZnJ+TGm9oYmluYMDAAACcPigI';
this.channel = 'convaiconsole_149700';
this.vadParams = { this.vadParams = {
interruptDurationMs: 160, interruptDurationMs: 160,
prefixPaddingMs: 300, prefixPaddingMs: 300,
@@ -69,12 +72,13 @@ class AgoraService {
* @param {string} channel - The channel name to join * @param {string} channel - The channel name to join
* @param {string} uid - The user ID (optional) * @param {string} uid - The user ID (optional)
*/ */
async join(token, channel, uid = null) { async join(agent_id, create_ts, status, uid = null) {
try { try {
this.uid = uid || `user_${Math.floor(Math.random() * 1000000)}`;
// Join the channel // 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; this.isJoined = true;
// Create and publish local audio track // Create and publish local audio track
@@ -94,7 +98,9 @@ class AgoraService {
// Enable volume indicator // Enable volume indicator
this.client.enableAudioVolumeIndicator(); this.client.enableAudioVolumeIndicator();
console.log("status:", this.status);
return true; return true;
} catch (error) { } catch (error) {
console.error('Error joining channel:', error); console.error('Error joining channel:', error);

View File

@@ -36,17 +36,24 @@ export const useChatStore = defineStore('chat', {
// Join the project // Join the project
const response = await apiService.joinProject(); const response = await apiService.joinProject();
// Join the Agora channel console.log('res:',response);
const { token, channel } = response.properties;
const agentRtcUid = response.properties.agent_rtc_uid;
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.isConnected = true;
this.error = null; this.error = null;
// Add greeting message // Add greeting message
const greetingMessage = response.properties.llm.greeting_message; // const greetingMessage = response.properties.llm.greeting_message;
const greetingMessage = "你好呀,有什么可以帮您?";
if (greetingMessage) { if (greetingMessage) {
this.addMessage({ this.addMessage({
id: Date.now(), id: Date.now(),