diff --git a/scene_state.json b/scene_state.json
new file mode 100644
index 0000000..261b13d
--- /dev/null
+++ b/scene_state.json
@@ -0,0 +1,3 @@
+{
+  "currentSceneIndex": 2
+}
\ No newline at end of file
diff --git a/server.js b/server.js
index f1a3202..95bdf6f 100644
--- a/server.js
+++ b/server.js
@@ -86,27 +86,58 @@ app.delete('/api/messages/clear', async (req, res) => {
 const connectedClients = new Map();
 
 // 场景轮询系统
-// 场景轮询系统
+// 场景轮询系统 - 添加持久化
+// 删除这行:const fs = require('fs');  // 重复声明,需要删除
+const sceneStateFile = path.join(__dirname, 'scene_state.json');
+
+// 从文件加载场景状态
+function loadSceneState() {
+  try {
+    if (fs.existsSync(sceneStateFile)) {
+      const data = fs.readFileSync(sceneStateFile, 'utf8');
+      const state = JSON.parse(data);
+      currentSceneIndex = state.currentSceneIndex || 0;
+      console.log(`从文件加载场景状态: ${currentSceneIndex} (${scenes[currentSceneIndex].name})`);
+    } else {
+      console.log('场景状态文件不存在,使用默认值: 0');
+    }
+  } catch (error) {
+    console.error('加载场景状态失败:', error);
+    currentSceneIndex = 0;
+  }
+}
+
+// 保存场景状态到文件
+function saveSceneState() {
+  try {
+    const state = { currentSceneIndex };
+    fs.writeFileSync(sceneStateFile, JSON.stringify(state, null, 2));
+    console.log(`场景状态已保存: ${currentSceneIndex}`);
+  } catch (error) {
+    console.error('保存场景状态失败:', error);
+  }
+}
+
 let currentSceneIndex = 0;
 const scenes = [
   {
     name: '起床',
-    defaultVideo: '8-4-bd-2.mp4',
-    interactionVideo: '8-4-sh.mp4',
+    defaultVideo: 'qc-bd-4.mp4',
+    interactionVideo: 'qc-sh-4.mp4',
     tag: 'wakeup',
     apiKey: 'bot-20250724150616-xqpz8' // 起床场景的API key
   },
   {
     name: '开车',
-    defaultVideo: '8-4-kc-bd.mp4',
-    interactionVideo: '8-4-kc-sh.mp4',
+    defaultVideo: 'kc-bd-3.mp4',
+    interactionVideo: 'kc-sh-3.mp4',
     tag: 'driving',
     apiKey: 'bot-20250623140339-r8f8b' // 开车场景的API key
   },
   {
     name: '喝茶',
-    defaultVideo: '8-4-hc-bd.mp4',
-    interactionVideo: '8-4-hc-sh.mp4',
+    defaultVideo: 'hc-bd-3.mp4',
+    interactionVideo: 'hc-sh-3(1).mp4',
     tag: 'tea',
     apiKey: 'bot-20250804180724-4dgtk' // 喝茶场景的API key
   }
@@ -117,11 +148,34 @@ function getCurrentScene() {
   return scenes[currentSceneIndex];
 }
 
-// 切换到下一个场景
+// 切换到下一个场景 - 改进版
 function switchToNextScene() {
+  const previousIndex = currentSceneIndex;
+  const previousScene = scenes[previousIndex].name;
+  
   currentSceneIndex = (currentSceneIndex + 1) % scenes.length;
-  console.log(`切换到场景: ${getCurrentScene().name}`);
-  return getCurrentScene();
+  const newScene = getCurrentScene();
+  
+  console.log(`场景切换: ${previousScene}(${previousIndex}) → ${newScene.name}(${currentSceneIndex})`);
+  
+  // 保存状态到文件
+  saveSceneState();
+  
+  return newScene;
+}
+
+// 在服务器启动时加载场景状态
+async function initializeServer() {
+    try {
+        // 加载场景状态
+        loadSceneState();
+        
+        await messageHistory.initialize();
+        console.log('消息历史初始化完成');
+        console.log(`当前场景: ${getCurrentScene().name} (索引: ${currentSceneIndex})`);
+    } catch (error) {
+        console.error('初始化服务器失败:', error);
+    }
 }
 
 // 视频映射配置 - 动态更新
@@ -185,8 +239,13 @@ app.get('/api/current-scene', (req, res) => {
 
 // 获取视频映射
 app.get('/api/video-mapping', (req, res) => {
-  // videoMapping = getCurrentScene()
-  res.json({ mapping: videoMapping });
+  const currentMapping = getVideoMapping();
+  const dynamicMapping = {
+    'default': currentMapping.defaultVideo,
+    '8-4-sh': currentMapping.interactionVideo,
+    'tag': currentMapping.tag
+  };
+  res.json({ mapping: dynamicMapping });
 });
 
 // 获取默认视频
@@ -203,7 +262,8 @@ io.on('connection', (socket) => {
   connectedClients.set(socket.id, {
     socket: socket,
     currentVideo: getDefaultVideo(),
-    isInInteraction: false
+    isInInteraction: false,
+    hasTriggeredSceneSwitch: false  // 添加这个标志
   });
 
   // 处理WebRTC信令 - 用于传输视频流
@@ -344,11 +404,25 @@ io.on('connection', (socket) => {
 
   // 处理用户关闭连接事件
   socket.on('user-disconnect', () => {
+    console.log('=== 场景切换开始 ===');
     console.log('用户主动关闭连接:', socket.id);
+    console.log('切换前场景:', getCurrentScene().name, '(索引:', currentSceneIndex, ')');
     
     // 切换到下一个场景
     const newScene = switchToNextScene();
-    console.log(`场景已切换到: ${newScene.name}`);
+    console.log('切换后场景:', newScene.name, '(索引:', currentSceneIndex, ')');
+    
+    // 检查是否已经处理过场景切换
+    const client = connectedClients.get(socket.id);
+    if (client && client.hasTriggeredSceneSwitch) {
+      console.log('场景切换已处理,跳过重复触发');
+      return;
+    }
+    
+    // 标记已处理场景切换
+    if (client) {
+      client.hasTriggeredSceneSwitch = true;
+    }
     
     // 更新videoMapping
     const newMapping = getVideoMapping();
@@ -356,20 +430,17 @@ io.on('connection', (socket) => {
     videoMapping['8-4-sh'] = newMapping.interactionVideo;
     videoMapping['tag'] = newMapping.tag;
     
-    console.log('videoMapping已更新:', videoMapping);
-    
-    // 清理客户端状态
-    const client = connectedClients.get(socket.id);
-    if (client) {
-      client.currentVideo = newMapping.defaultVideo;
-      client.isInInteraction = false;
-    }
-    
     // 广播场景切换事件给所有客户端
     io.emit('scene-switched', {
-      scene: newScene,
-      mapping: newMapping,
-      from: socket.id
+        scene: newScene,
+        mapping: {
+            defaultVideo: newMapping.defaultVideo,
+            interactionVideo: newMapping.interactionVideo,
+            tag: newMapping.tag,
+            'default': newMapping.defaultVideo,
+            '8-4-sh': newMapping.interactionVideo
+        },
+        from: socket.id
     });
   });
 
diff --git a/src/index.html b/src/index.html
deleted file mode 100644
index 0809ed4..0000000
--- a/src/index.html
+++ /dev/null
@@ -1,408 +0,0 @@
-
-
-
-    
-    
-    Soulmate In Parallels - 壹和零人工智能
-    
-    
-    
-
-
-    
-        
-        
-            WebRTC 音频通话
-            实时播放录制视频,支持文本和语音输入
-        
-
-        
-            
-            
-
-            
-            
-                
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                
-                
-                
-                    未选择视频
-                
-            
-
-            
-            
-                
-                
-            
-
-            
-            
-
-            
-            
-
-            
-            
-        
-