From cd629ebc2899c4bb30b51ce5f99a84574804f863 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 31 七月 2026 15:40:21 +0800
Subject: [PATCH] 银川 1.API密钥管理页面开发联调 2.模型管理页面开发联调 3.知识库管理页面开发联调 4.通知公告页面开发联调

---
 src/views/im/home/composables/useMediaStreamElement.ts |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/views/im/home/composables/useMediaStreamElement.ts b/src/views/im/home/composables/useMediaStreamElement.ts
new file mode 100644
index 0000000..aa6ae09
--- /dev/null
+++ b/src/views/im/home/composables/useMediaStreamElement.ts
@@ -0,0 +1,40 @@
+import { type VNodeRef, watch } from 'vue'
+
+/**
+ * 鎶婂搷搴斿紡 MediaStream 鎸傚埌 `<video>` / `<audio>` 鍏冪礌鐨� srcObject 涓婏紱
+ * stream 涓虹┖鏃舵竻鎺� srcObject锛岄伩鍏嶈澶囧叧闂悗鐢婚潰鍗″湪鏈�鍚庝竴甯�
+ */
+export function useMediaStreamElement<T extends HTMLMediaElement>(
+  streamSource: () => MediaStream | null | undefined
+): VNodeRef {
+  let el: T | null = null
+  let currentStream: MediaStream | null | undefined
+
+  const syncStream = () => {
+    if (el) {
+      el.srcObject = currentStream || null
+    }
+  }
+
+  watch(
+    streamSource,
+    (stream) => {
+      currentStream = stream
+      syncStream()
+    },
+    { flush: 'post', immediate: true }
+  )
+
+  return (value) => {
+    if (value instanceof HTMLMediaElement) {
+      el = value as T
+      syncStream()
+      return
+    }
+
+    if (el) {
+      el.srcObject = null
+    }
+    el = null
+  }
+}

--
Gitblit v1.9.3