yanqiliang 5 месяцев назад
Родитель
Сommit
0d0243b539
2 измененных файлов с 611 добавлено и 1 удалено
  1. 168 0
      src/assets/scss/style.scss
  2. 443 1
      src/pages/home/Index.jsx

+ 168 - 0
src/assets/scss/style.scss

@@ -113,6 +113,174 @@ html{
   padding: 0.4rem;
   font-size: 1.2rem;
 }
+.debug-status-pill {
+  position: fixed;
+  right: 0.6rem;
+  bottom: 3.4rem;
+  z-index: 20;
+  display: inline-flex;
+  align-items: center;
+  gap: 5px;
+  box-sizing: border-box;
+  max-width: 70vw;
+  min-height: 28px;
+  padding: 4px 8px;
+  border: 1px solid rgba(13, 39, 100, 0.25);
+  border-radius: 4px;
+  background: rgba(255, 255, 255, 0.92);
+  color: #0d2764;
+  font-size: 12px;
+  line-height: 18px;
+  vertical-align: middle;
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+
+  span {
+    overflow: hidden;
+    text-overflow: ellipsis;
+  }
+}
+.debug-modal {
+  max-width: 1200px;
+
+  .adm-modal-body {
+    max-height: 78vh;
+    overflow-y: auto;
+  }
+}
+.debug-panel {
+  color: #222;
+  font-size: 13px;
+  line-height: 1.45;
+  text-align: left;
+}
+.debug-summary-grid {
+  display: block;
+}
+.debug-section {
+  padding: 8px 0;
+  border-bottom: 1px solid #eee;
+
+  &:last-child {
+    border-bottom: 0;
+  }
+}
+.debug-section-title {
+  margin-bottom: 6px;
+  color: #0d2764;
+  font-size: 14px;
+  font-weight: 600;
+}
+.debug-row {
+  display: flex;
+  align-items: flex-start;
+  min-height: 24px;
+  gap: 10px;
+}
+.debug-label {
+  flex: 0 0 78px;
+  color: #666;
+}
+.debug-value {
+  flex: 1;
+  min-width: 0;
+  color: #222;
+  word-break: break-all;
+
+  &.long {
+    font-family: Consolas, Monaco, monospace;
+    font-size: 12px;
+  }
+}
+.debug-log-list {
+  max-height: 180px;
+  overflow-y: auto;
+  border: 1px solid #eee;
+  border-radius: 4px;
+}
+.debug-log-item {
+  display: grid;
+  grid-template-columns: 66px 58px minmax(0, 1fr);
+  gap: 6px;
+  padding: 6px 8px;
+  border-bottom: 1px solid #f2f2f2;
+  font-size: 12px;
+  line-height: 18px;
+
+  &:last-child {
+    border-bottom: 0;
+  }
+}
+.debug-log-time {
+  color: #666;
+  font-family: Consolas, Monaco, monospace;
+}
+.debug-log-type {
+  color: #1e50a1;
+  font-weight: 600;
+}
+.debug-log-message {
+  min-width: 0;
+  color: #222;
+  word-break: break-word;
+}
+.debug-empty {
+  padding: 10px;
+  color: #999;
+  text-align: center;
+}
+
+@media (orientation: landscape) and (min-width: 900px) {
+  .debug-status-pill {
+    bottom: 3rem;
+  }
+
+  .debug-modal {
+    max-width: none;
+
+    .adm-modal-body {
+      max-height: 76vh;
+    }
+  }
+
+  .debug-panel {
+    font-size: 14px;
+  }
+
+  .debug-summary-grid {
+    display: grid;
+    grid-template-columns: repeat(3, minmax(0, 1fr));
+    gap: 14px;
+  }
+
+  .debug-summary-grid .debug-section {
+    min-width: 0;
+    padding: 0 12px 0 0;
+    border-right: 1px solid #eee;
+    border-bottom: 0;
+
+    &:last-child {
+      border-right: 0;
+    }
+  }
+
+  .debug-log-section {
+    margin-top: 10px;
+    padding-top: 10px;
+    border-top: 1px solid #eee;
+    border-bottom: 0;
+  }
+
+  .debug-log-list {
+    max-height: 260px;
+  }
+
+  .debug-log-item {
+    grid-template-columns: 76px 66px minmax(0, 1fr);
+    font-size: 13px;
+  }
+}
 .page-body {
   margin: 0;
   padding: 0.6rem;

+ 443 - 1
src/pages/home/Index.jsx

@@ -6,7 +6,7 @@ import BigScreenOld from '@pages/bigScreen/IndexOld.jsx';
 import OperateScreen from '@pages/operateScreen/Index.jsx';
 import FingerprintJS from '@fingerprintjs/fingerprintjs';
 import { initSocket } from '@api/index.js';
-import { AntOutline, SetOutline } from 'antd-mobile-icons';
+import { AntOutline, ContentOutline, SetOutline } from 'antd-mobile-icons';
 import { Modal } from 'antd-mobile';
 
 class Home extends React.Component {
@@ -52,6 +52,34 @@ class Home extends React.Component {
         lastError: '',
         updatedAt: '',
       },
+      debugPanelVisible: false,
+      debugInfo: {
+        socketStatus: 'unknown',
+        socketConnected: false,
+        socketId: '',
+        lastConnectAt: '',
+        lastDisconnectAt: '',
+        lastDisconnectReason: '',
+        reconnectAttempt: 0,
+        receiveCount: 0,
+        lastReceiveAt: '',
+        lastReceiveAtMs: 0,
+        lastMessageSize: 0,
+        lastRoomDesc: '',
+        lastUpdateTime: '',
+        lastVoiceFileName: '',
+        parseErrorCount: 0,
+        ignoredNoCallMsgCount: 0,
+        ignoredNoVoiceCount: 0,
+        voiceQueueLength: 0,
+        lastEnqueueAt: '',
+        lastAudioUrl: '',
+        lastAudioStatus: 'idle',
+        lastAudioError: '',
+        lastConnectAtMs: 0,
+        debugNowAt: Date.now(),
+        logs: [],
+      },
     };
     this.audioTimeoutId = null;
     this.activeAudioSrc = '';
@@ -61,13 +89,203 @@ class Home extends React.Component {
     this.audioSeq = 0;
     this.isAudioBusy = false;
     this.ignoreNextLegacyAudioCallback = false;
+    this.debugTickTimer = null;
   }
+
+  getNowTime = () => new Date().toLocaleTimeString('zh-CN', { hour12: false });
+
+  formatDuration = (durationMs) => {
+    if (durationMs === undefined || durationMs === null) {
+      return '-';
+    }
+    const totalSeconds = Math.max(0, Math.floor(durationMs / 1000));
+    const hours = Math.floor(totalSeconds / 3600);
+    const minutes = Math.floor((totalSeconds % 3600) / 60);
+    const seconds = totalSeconds % 60;
+    if (hours > 0) {
+      return `${hours}小时${minutes}分`;
+    }
+    if (minutes > 0) {
+      return `${minutes}分${seconds}秒`;
+    }
+    return `${seconds}秒`;
+  };
+
+  getSilentDurationMs = (debugInfo = this.state.debugInfo) => {
+    const baseTime = debugInfo.lastReceiveAtMs || debugInfo.lastConnectAtMs;
+    if (!baseTime) {
+      return null;
+    }
+    return Math.max(0, (debugInfo.debugNowAt || Date.now()) - baseTime);
+  };
+
+  getSilentDurationText = (debugInfo = this.state.debugInfo) => (
+    this.formatDuration(this.getSilentDurationMs(debugInfo))
+  );
+
+  startDebugTicker = () => {
+    if (this.debugTickTimer) {
+      clearInterval(this.debugTickTimer);
+    }
+    this.debugTickTimer = setInterval(() => {
+      this.setState((prevState) => ({
+        debugInfo: {
+          ...prevState.debugInfo,
+          debugNowAt: Date.now(),
+        },
+      }));
+    }, 30000);
+  };
+
+  getSocketId = () => {
+    try {
+      return window.socket?.id || '';
+    } catch {
+      return '';
+    }
+  };
+
+  getSocketConnected = () => {
+    try {
+      return !!window.socket?.connected;
+    } catch {
+      return false;
+    }
+  };
+
+  getShortFileName = (value = '') => {
+    const text = String(value || '');
+    if (!text) {
+      return '';
+    }
+    const cleanText = text.split('?')[0];
+    const parts = cleanText.split('/');
+    return parts[parts.length - 1] || text.slice(-80);
+  };
+
+  appendDebugLog = (debugInfo, type, message) => {
+    const logs = [
+      {
+        time: this.getNowTime(),
+        type,
+        message,
+      },
+      ...(debugInfo.logs || []),
+    ].slice(0, 100);
+    return {
+      ...debugInfo,
+      logs,
+    };
+  };
+
+  updateDebugInfo = (updater, log) => {
+    this.setState((prevState) => {
+      const patch = typeof updater === 'function'
+        ? updater(prevState.debugInfo, prevState)
+        : (updater || {});
+      let debugInfo = {
+        ...prevState.debugInfo,
+        ...patch,
+      };
+      if (log) {
+        debugInfo = this.appendDebugLog(debugInfo, log.type, log.message);
+      }
+      return { debugInfo };
+    });
+  };
+
+  openDebugPanel = () => {
+    this.setState({ debugPanelVisible: true });
+  };
+
+  hideDebugPanel = () => {
+    this.setState({ debugPanelVisible: false });
+  };
+
+  clearDebugLogs = () => {
+    this.setState((prevState) => ({
+      debugInfo: {
+        ...prevState.debugInfo,
+        logs: [],
+      },
+    }));
+  };
+
+  renderDebugRow = (label, value, className = '') => (
+    <div className="debug-row">
+      <span className="debug-label">{label}</span>
+      <span className={`debug-value ${className}`}>
+        {value === undefined || value === null || value === '' ? '-' : value}
+      </span>
+    </div>
+  );
+
+  renderDebugPanel = () => {
+    const { debugInfo } = this.state;
+    const socketText = debugInfo.socketConnected ? '已连接' : '未连接';
+    const silentText = this.getSilentDurationText(debugInfo);
+    return (
+      <div className="debug-panel">
+        <div className="debug-summary-grid">
+          <div className="debug-section">
+            <div className="debug-section-title">设备与连接</div>
+            {this.renderDebugRow('设备ID', this.state.deviceID, 'long')}
+            {this.renderDebugRow('连接状态', `${socketText} / ${debugInfo.socketStatus}`)}
+            {this.renderDebugRow('Socket ID', debugInfo.socketId, 'long')}
+            {this.renderDebugRow('最后连接', debugInfo.lastConnectAt)}
+            {this.renderDebugRow('最后断开', debugInfo.lastDisconnectAt)}
+            {this.renderDebugRow('断开原因', debugInfo.lastDisconnectReason, 'long')}
+            {this.renderDebugRow('重连次数', debugInfo.reconnectAttempt)}
+          </div>
+          <div className="debug-section">
+            <div className="debug-section-title">消息接收</div>
+            {this.renderDebugRow('收到次数', debugInfo.receiveCount)}
+            {this.renderDebugRow('最后收包', debugInfo.lastReceiveAt)}
+            {this.renderDebugRow('已静默', silentText)}
+            {this.renderDebugRow('消息大小', debugInfo.lastMessageSize ? `${debugInfo.lastMessageSize} 字符` : '')}
+            {this.renderDebugRow('诊室', debugInfo.lastRoomDesc)}
+            {this.renderDebugRow('更新时间', debugInfo.lastUpdateTime)}
+            {this.renderDebugRow('语音文件', debugInfo.lastVoiceFileName, 'long')}
+            {this.renderDebugRow('解析失败', debugInfo.parseErrorCount)}
+            {this.renderDebugRow('无callMsg', debugInfo.ignoredNoCallMsgCount)}
+            {this.renderDebugRow('无语音字段', debugInfo.ignoredNoVoiceCount)}
+          </div>
+          <div className="debug-section">
+            <div className="debug-section-title">语音队列</div>
+            {this.renderDebugRow('队列长度', debugInfo.voiceQueueLength)}
+            {this.renderDebugRow('最后入队', debugInfo.lastEnqueueAt)}
+            {this.renderDebugRow('播放状态', debugInfo.lastAudioStatus)}
+            {this.renderDebugRow('播放错误', debugInfo.lastAudioError, 'long')}
+            {this.renderDebugRow('音频地址', debugInfo.lastAudioUrl, 'long')}
+          </div>
+        </div>
+        <div className="debug-section debug-log-section">
+          <div className="debug-section-title">最近日志</div>
+          <div className="debug-log-list">
+            {debugInfo.logs.length ? debugInfo.logs.map((item, index) => (
+              <div className="debug-log-item" key={`${item.time}-${index}`}>
+                <span className="debug-log-time">{item.time}</span>
+                <span className="debug-log-type">{item.type}</span>
+                <span className="debug-log-message">{item.message}</span>
+              </div>
+            )) : <div className="debug-empty">暂无日志</div>}
+          </div>
+        </div>
+      </div>
+    );
+  };
+
   componentDidMount() {
+    this.startDebugTicker();
     this.initDevice();
     this.initAndroidVoice();
   }
   componentWillUnmount() {
     this.clearAudioWatchdog();
+    if (this.debugTickTimer) {
+      clearInterval(this.debugTickTimer);
+      this.debugTickTimer = null;
+    }
     this.isAudioBusy = false;
     // 解绑全局桥接回调,避免热更新 / 重挂载后产生幽灵回调
     try {
@@ -89,6 +307,14 @@ class Home extends React.Component {
     // 老 APK 无此回调时不影响正常逻辑
     window.onNativeReady = () => {
       console.warn('收到 onNativeReady,复位音频状态');
+      this.updateDebugInfo({
+        lastAudioStatus: 'native-ready',
+        lastAudioError: '',
+        voiceQueueLength: this.state.voiceList.length,
+      }, {
+        type: 'native',
+        message: '收到 onNativeReady',
+      });
       this.clearAudioWatchdog();
       this.activeAudioSrc = '';
       this.activeAudioStartAt = 0;
@@ -111,6 +337,14 @@ class Home extends React.Component {
 
   skipCurrentVoice = (reason) => {
     console.error(`音频播放失败,跳过当前音频(${reason}): ${this.state.voiceList[0]}`);
+    this.updateDebugInfo({
+      lastAudioStatus: 'skip',
+      lastAudioError: reason,
+      voiceQueueLength: Math.max(this.state.voiceList.length - 1, 0),
+    }, {
+      type: 'audio',
+      message: `跳过音频: ${reason}`,
+    });
     this.activeAudioSrc = '';
     this.activeAudioStartAt = 0;
     this.activeAudioId = '';
@@ -150,11 +384,24 @@ class Home extends React.Component {
       this.activeAudioId = '';
       this.activeAudioSupportsPlayId = false;
       this.isAudioBusy = false;
+      this.updateDebugInfo({
+        lastAudioStatus: 'idle',
+        lastAudioError: '',
+        voiceQueueLength: 0,
+      });
       this.setState({ myStatus: false, audioRetryCount: 0 });
       return;
     }
 
     if (flag === 'success') {
+      this.updateDebugInfo({
+        lastAudioStatus: 'success',
+        lastAudioError: '',
+        voiceQueueLength: Math.max(this.state.voiceList.length - 1, 0),
+      }, {
+        type: 'audio',
+        message: `播放完成: ${this.getShortFileName(this.state.voiceList[0])}`,
+      });
       this.activeAudioSrc = '';
       this.activeAudioStartAt = 0;
       this.activeAudioId = '';
@@ -176,6 +423,14 @@ class Home extends React.Component {
     // 避免 ON_PAUSE/ON_RESUME 频繁切换导致同一号被 retry 耗尽后丢掉
     if (flag === 'paused') {
       console.warn('音频因后台暂停中断,恢复后重新播放当前号');
+      this.updateDebugInfo({
+        lastAudioStatus: 'paused',
+        lastAudioError: '',
+        voiceQueueLength: this.state.voiceList.length,
+      }, {
+        type: 'audio',
+        message: '播放因后台暂停中断',
+      });
       this.activeAudioSrc = '';
       this.activeAudioStartAt = 0;
       this.activeAudioId = '';
@@ -190,6 +445,14 @@ class Home extends React.Component {
     const elapsed = Date.now() - this.activeAudioStartAt;
     if (retryCount <= this.MAX_AUDIO_RETRY && elapsed < this.AUDIO_TOTAL_TIMEOUT_MS) {
       console.warn(`音频播放失败,第 ${retryCount} 次重试: ${this.state.voiceList[0]}`);
+      this.updateDebugInfo({
+        lastAudioStatus: 'retrying',
+        lastAudioError: flag,
+        voiceQueueLength: this.state.voiceList.length,
+      }, {
+        type: 'audio',
+        message: `播放失败重试 ${retryCount}: ${flag}`,
+      });
       this.setState({ audioRetryCount: retryCount }, () => {
         this.soundPaly();
       });
@@ -210,6 +473,14 @@ class Home extends React.Component {
     }
 
     if (status === 'started') {
+      this.updateDebugInfo({
+        lastAudioStatus: 'started',
+        lastAudioError: '',
+        voiceQueueLength: this.state.voiceList.length,
+      }, {
+        type: 'audio',
+        message: `开始播放: ${this.getShortFileName(this.activeAudioSrc)}`,
+      });
       this.clearAudioWatchdog();
       this.audioTimeoutId = setTimeout(() => {
         console.error(`音频播放中超时(${this.AUDIO_PLAYING_TIMEOUT_MS}ms),强制跳转: ${this.activeAudioSrc}`);
@@ -254,11 +525,28 @@ class Home extends React.Component {
       const elapsed = Date.now() - this.activeAudioStartAt;
       const remaining = totalTimeoutMs - elapsed;
       if (remaining <= 0) {
+        this.updateDebugInfo({
+          lastAudioStatus: 'timeout',
+          lastAudioError: 'total-timeout',
+          voiceQueueLength: this.state.voiceList.length,
+        }, {
+          type: 'audio',
+          message: `音频总时长超时: ${this.getShortFileName(src)}`,
+        });
         this.skipCurrentVoice('timeout');
         return;
       }
 
       this.isAudioBusy = true;
+      this.updateDebugInfo({
+        lastAudioStatus: 'starting',
+        lastAudioError: '',
+        lastAudioUrl: src,
+        voiceQueueLength: this.state.voiceList.length,
+      }, {
+        type: 'audio',
+        message: `准备播放: ${this.getShortFileName(src)}`,
+      });
       this.setState(
         {
           myStatus: true,
@@ -276,6 +564,14 @@ class Home extends React.Component {
             );
             this.audioTimeoutId = setTimeout(() => {
               console.error(`音频启动超时(${timeoutMs}ms),强制跳转: ${src}`);
+              this.updateDebugInfo({
+                lastAudioStatus: 'timeout',
+                lastAudioError: `start-timeout-${timeoutMs}ms`,
+                voiceQueueLength: this.state.voiceList.length,
+              }, {
+                type: 'audio',
+                message: `启动超时: ${this.getShortFileName(src)}`,
+              });
               if (!this.activeAudioSupportsPlayId) {
                 this.ignoreNextLegacyAudioCallback = true;
               }
@@ -293,6 +589,14 @@ class Home extends React.Component {
             }
           } else {
             console.error(`audio bridge unavailable, skip: ${src}`);
+            this.updateDebugInfo({
+              lastAudioStatus: 'bridge-unavailable',
+              lastAudioError: 'audio bridge unavailable',
+              voiceQueueLength: this.state.voiceList.length,
+            }, {
+              type: 'audio',
+              message: 'Android 播放桥不可用',
+            });
             this.handleMediaPlayOver('error');
           }
         },
@@ -303,6 +607,11 @@ class Home extends React.Component {
       this.activeAudioId = '';
       this.activeAudioSupportsPlayId = false;
       this.isAudioBusy = false;
+      this.updateDebugInfo({
+        lastAudioStatus: 'idle',
+        lastAudioError: '',
+        voiceQueueLength: 0,
+      });
       this.setState({
         myStatus: false,
       });
@@ -401,6 +710,35 @@ class Home extends React.Component {
   };
   handleSocketStatus = (status = {}) => {
     const updatedAt = new Date().toLocaleTimeString('zh-CN', { hour12: false });
+    const updatedAtMs = Date.now();
+    const socketStatus = status.status || this.state.debugInfo.socketStatus;
+    const socketId = status.socketId || this.getSocketId();
+    const socketConnected = this.getSocketConnected() || socketStatus === 'connected';
+    const debugPatch = {
+      socketStatus,
+      socketConnected,
+      socketId,
+    };
+    let log = null;
+    if (socketStatus === 'connected') {
+      debugPatch.lastConnectAt = updatedAt;
+      debugPatch.lastConnectAtMs = updatedAtMs;
+      debugPatch.debugNowAt = updatedAtMs;
+      debugPatch.lastDisconnectReason = '';
+      debugPatch.reconnectAttempt = status.attempt || 0;
+      log = { type: 'socket', message: `连接成功 ${socketId || ''}`.trim() };
+    } else if (socketStatus === 'disconnected') {
+      debugPatch.lastDisconnectAt = updatedAt;
+      debugPatch.lastDisconnectReason = status.lastError || '';
+      log = { type: 'socket', message: `连接断开: ${status.lastError || '-'}` };
+    } else if (socketStatus === 'reconnecting') {
+      debugPatch.reconnectAttempt = status.attempt || this.state.debugInfo.reconnectAttempt;
+      log = { type: 'socket', message: status.message || '长连接重连中' };
+    } else if (socketStatus === 'error' || socketStatus === 'failed' || socketStatus === 'timeout') {
+      debugPatch.lastDisconnectReason = status.lastError || status.message || '';
+      log = { type: 'socket', message: status.message || socketStatus };
+    }
+    this.updateDebugInfo(debugPatch, log);
     this.setState((prevState) => ({
       socketStatus: {
         ...prevState.socketStatus,
@@ -421,6 +759,10 @@ class Home extends React.Component {
           message: '长连接已连接',
           lastError: '',
         });
+        this.updateDebugInfo(null, {
+          type: 'socket',
+          message: '手动重连时 socket 仍显示已连接',
+        });
         return;
       }
       window.socket.connect();
@@ -463,10 +805,34 @@ class Home extends React.Component {
       obj,
       (data) => {
         // console.log('Room接收消息:', data);
+        const rawData = data;
+        const receiveAt = this.getNowTime();
+        const receiveAtMs = Date.now();
+        const messageSize = typeof rawData === 'string'
+          ? rawData.length
+          : JSON.stringify(rawData || {}).length;
+        this.updateDebugInfo((debugInfo) => ({
+          receiveCount: debugInfo.receiveCount + 1,
+          lastReceiveAt: receiveAt,
+          lastReceiveAtMs: receiveAtMs,
+          debugNowAt: receiveAtMs,
+          lastMessageSize: messageSize,
+          socketConnected: this.getSocketConnected(),
+          socketId: this.getSocketId(),
+        }), {
+          type: 'socket',
+          message: `收到 callNumber (${messageSize} 字符)`,
+        });
         try {
           data = typeof data === 'string' ? JSON.parse(data) : data;
         } catch (error) {
           console.error('叫号消息解析失败:', error, data);
+          this.updateDebugInfo((debugInfo) => ({
+            parseErrorCount: debugInfo.parseErrorCount + 1,
+          }), {
+            type: 'message',
+            message: '叫号消息 JSON 解析失败',
+          });
           return;
         }
         if (data.callMsg) {
@@ -485,6 +851,17 @@ class Home extends React.Component {
           const voiceUrl = (data.path && data.voiceFileName)
             ? String(data.path) + String(data.voiceFileName)
             : null;
+          const voiceFileName = data?.voiceFileName || '';
+          this.updateDebugInfo((debugInfo) => ({
+            lastRoomDesc: data?.roomDesc || '',
+            lastUpdateTime: data?.callMsg?.updateTime || '',
+            lastVoiceFileName: voiceFileName,
+            ignoredNoVoiceCount: voiceUrl ? debugInfo.ignoredNoVoiceCount : debugInfo.ignoredNoVoiceCount + 1,
+            lastAudioUrl: voiceUrl || debugInfo.lastAudioUrl,
+          }), {
+            type: 'message',
+            message: `解析成功 room=${data?.roomDesc || '-'} voice=${this.getShortFileName(voiceFileName) || '-'}`,
+          });
           this.setState(
             (prevState) => {
               // 使用 prevState 保证高并发消息下不丢更新(避免覆盖前一条 roomObjtmp)
@@ -502,6 +879,26 @@ class Home extends React.Component {
                   nextVoiceList = nextVoiceList.slice(dropCount);
                 }
               }
+              let nextDebugInfo = {
+                ...prevState.debugInfo,
+                voiceQueueLength: nextVoiceList.length,
+              };
+              if (voiceUrl) {
+                const droppedCount = prevState.voiceList.length + 1 - nextVoiceList.length;
+                if (droppedCount > 0) {
+                  nextDebugInfo = this.appendDebugLog(
+                    nextDebugInfo,
+                    'queue',
+                    `队列超过 ${this.MAX_VOICE_QUEUE},丢弃 ${droppedCount} 条`,
+                  );
+                }
+                nextDebugInfo = this.appendDebugLog({
+                    ...nextDebugInfo,
+                    voiceQueueLength: nextVoiceList.length,
+                    lastEnqueueAt: this.getNowTime(),
+                    lastAudioUrl: voiceUrl,
+                  }, 'queue', `语音入队: ${this.getShortFileName(voiceFileName)}`);
+              }
               return {
                 userData: {
                   ...data?.userData,
@@ -518,6 +915,7 @@ class Home extends React.Component {
                 roomObjtmp,
                 patListArea: newArray,
                 voiceList: nextVoiceList,
+                debugInfo: nextDebugInfo,
               };
             },
             () => {
@@ -526,6 +924,13 @@ class Home extends React.Component {
               }
             },
           );
+        } else {
+          this.updateDebugInfo((debugInfo) => ({
+            ignoredNoCallMsgCount: debugInfo.ignoredNoCallMsgCount + 1,
+          }), {
+            type: 'message',
+            message: '收到消息但缺少 callMsg,已忽略',
+          });
         }
       },
       this.handleSocketStatus,
@@ -640,6 +1045,33 @@ class Home extends React.Component {
               </div>
             }
           />
+          <Modal
+            visible={this.state.debugPanelVisible}
+            title='现场诊断'
+            closeOnMaskClick={true}
+            showCloseButton={true}
+            onClose={this.hideDebugPanel}
+            className="debug-modal"
+            style={{ width: '92vw' }}
+            actions={[
+              {
+                key: 'clear',
+                text: '清空日志',
+              },
+              {
+                key: 'close',
+                text: '关闭',
+              },
+            ]}
+            onAction={(action) => {
+              if (action.key === 'clear') {
+                this.clearDebugLogs();
+                return;
+              }
+              this.hideDebugPanel();
+            }}
+            content={this.renderDebugPanel()}
+          />
           {this.state.showType == 'doctor' ? (
             <DoctorScreen
               userData={this.state.userData}
@@ -682,6 +1114,16 @@ class Home extends React.Component {
                 {this.state?.updateTime || ''}
               </span>
             )}
+            <span
+              className="debug-status-pill"
+              onClick={this.openDebugPanel}
+              title="现场诊断"
+            >
+              <ContentOutline />
+              <span>
+                长连:{this.state.debugInfo.socketConnected ? '已连' : '未连'} 静默:{this.getSilentDurationText()} 队列:{this.state.debugInfo.voiceQueueLength}
+              </span>
+            </span>
             <AntOutline
               style={{
                 color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',