2
0
Selaa lähdekoodia

✨ feat(demo): 集成RTC管理器功能

- 添加rtcManager变量及初始化逻辑,实现STT、RTM和RTC管理器的完整集成
- 修改textstreamReceived事件监听,从rtmManager迁移到rtcManager
- 增强testTranscription函数,添加RTC频道加入、音视频轨道创建和发布流程
- 延长转录测试时长从5秒到10秒,确保音视频流有足够时间传输
- 添加RTC管理器销毁逻辑到cleanup函数,完善资源释放流程
- 优化错误检查,确保STT和RTC管理器都初始化后才允许转录操作
- 更新日志提示信息,反映新增的RTC功能状态变化
yourname 2 kuukautta sitten
vanhempi
sitoutus
f960b3ac8d
1 muutettua tiedostoa jossa 46 lisäystä ja 7 poistoa
  1. 46 7
      public/umd-demo.html

+ 46 - 7
public/umd-demo.html

@@ -413,7 +413,9 @@
       let sdk = null
       let sttManager = null
       let rtmManager = null
+      let rtcManager = null
       let isSdkInitialized = false
+      let isRtcManagerJoined = false
 
       // 添加测试日志
       function addTestLog(message, type = "info") {
@@ -529,6 +531,7 @@
               // 创建管理器
               rtmManager = sdk.createRtmManager()
               sttManager = sdk.createSttManager(rtmManager)
+              rtcManager = sdk.createRtcManager()
 
               // 监听RTM事件
               rtmManager.on("sttDataChanged", (data) => {
@@ -536,12 +539,12 @@
               })
 
               // 监听RTC文本流事件
-              rtmManager.on("textstreamReceived", (textstream) => {
+              rtcManager.on("textstreamReceived", (textstream) => {
                 addTestLog("收到文本流数据: " + JSON.stringify(textstream))
                 updateRealtimeDisplay(textstream)
               })
 
-              addTestLog("STT和RTM管理器创建成功", "success")
+              addTestLog("STT、RTM和RTC管理器创建成功", "success")
               document.getElementById("transcribeBtn").disabled = false
               document.getElementById("cleanupBtn").disabled = false
             })
@@ -555,8 +558,8 @@
 
       // 测试转录功能
       function testTranscription() {
-        if (!sttManager) {
-          addTestLog("STT管理器未初始化", "error")
+        if (!sttManager || !rtcManager) {
+          addTestLog("STT管理器或RTC管理器未初始化", "error")
           return
         }
 
@@ -567,16 +570,39 @@
 
         // 生成随机用户ID
         const genRandomUserId = () => Math.floor(Math.random() * 1000000)
+        const userId = genRandomUserId()
 
         sttManager
           .init({
-            userId: genRandomUserId(),
+            userId: userId,
             channel: channel,
             userName: userName,
           })
           .then(() => {
             addTestLog("STT管理器初始化成功", "success")
 
+            // 加入RTC频道
+            return rtcManager.join({
+              channel: channel,
+              userId: userId,
+            })
+          })
+          .then(() => {
+            addTestLog("RTC频道加入成功", "success")
+            isRtcManagerJoined = true
+
+            // 创建音视频轨道
+            return rtcManager.createTracks()
+          })
+          .then(() => {
+            addTestLog("音视频轨道创建成功", "success")
+
+            // 发布音视频流
+            return rtcManager.publish()
+          })
+          .then(() => {
+            addTestLog("音视频流发布成功", "success")
+
             // 开始转录
             return sttManager.startTranscription({
               languages: [{ source: "zh-CN" }],
@@ -585,7 +611,7 @@
           .then(() => {
             addTestLog("转录功能启动成功", "success")
 
-            // 模拟5秒后停止转录
+            // 模拟10秒后停止转录
             setTimeout(() => {
               if (sttManager) {
                 sttManager
@@ -597,7 +623,7 @@
                     addTestLog("停止转录失败: " + error, "error")
                   })
               }
-            }, 5000)
+            }, 10000)
           })
           .catch((error) => {
             addTestLog("转录功能测试失败: " + error, "error")
@@ -641,6 +667,19 @@
             })
         }
 
+        if (rtcManager) {
+          rtcManager
+            .destroy()
+            .then(() => {
+              addTestLog("RTC管理器销毁成功", "success")
+              rtcManager = null
+              isRtcManagerJoined = false
+            })
+            .catch((error) => {
+              addTestLog("RTC管理器销毁失败: " + error, "error")
+            })
+        }
+
         if (sdk) {
           sdk
             .destroy()