|
@@ -6,7 +6,7 @@ import BigScreenOld from '@pages/bigScreen/IndexOld.jsx';
|
|
|
import OperateScreen from '@pages/operateScreen/Index.jsx';
|
|
import OperateScreen from '@pages/operateScreen/Index.jsx';
|
|
|
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
|
import { initSocket } from '@api/index.js';
|
|
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';
|
|
import { Modal } from 'antd-mobile';
|
|
|
|
|
|
|
|
class Home extends React.Component {
|
|
class Home extends React.Component {
|
|
@@ -52,6 +52,34 @@ class Home extends React.Component {
|
|
|
lastError: '',
|
|
lastError: '',
|
|
|
updatedAt: '',
|
|
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.audioTimeoutId = null;
|
|
|
this.activeAudioSrc = '';
|
|
this.activeAudioSrc = '';
|
|
@@ -61,13 +89,203 @@ class Home extends React.Component {
|
|
|
this.audioSeq = 0;
|
|
this.audioSeq = 0;
|
|
|
this.isAudioBusy = false;
|
|
this.isAudioBusy = false;
|
|
|
this.ignoreNextLegacyAudioCallback = 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() {
|
|
componentDidMount() {
|
|
|
|
|
+ this.startDebugTicker();
|
|
|
this.initDevice();
|
|
this.initDevice();
|
|
|
this.initAndroidVoice();
|
|
this.initAndroidVoice();
|
|
|
}
|
|
}
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
|
this.clearAudioWatchdog();
|
|
this.clearAudioWatchdog();
|
|
|
|
|
+ if (this.debugTickTimer) {
|
|
|
|
|
+ clearInterval(this.debugTickTimer);
|
|
|
|
|
+ this.debugTickTimer = null;
|
|
|
|
|
+ }
|
|
|
this.isAudioBusy = false;
|
|
this.isAudioBusy = false;
|
|
|
// 解绑全局桥接回调,避免热更新 / 重挂载后产生幽灵回调
|
|
// 解绑全局桥接回调,避免热更新 / 重挂载后产生幽灵回调
|
|
|
try {
|
|
try {
|
|
@@ -89,6 +307,14 @@ class Home extends React.Component {
|
|
|
// 老 APK 无此回调时不影响正常逻辑
|
|
// 老 APK 无此回调时不影响正常逻辑
|
|
|
window.onNativeReady = () => {
|
|
window.onNativeReady = () => {
|
|
|
console.warn('收到 onNativeReady,复位音频状态');
|
|
console.warn('收到 onNativeReady,复位音频状态');
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'native-ready',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ voiceQueueLength: this.state.voiceList.length,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ type: 'native',
|
|
|
|
|
+ message: '收到 onNativeReady',
|
|
|
|
|
+ });
|
|
|
this.clearAudioWatchdog();
|
|
this.clearAudioWatchdog();
|
|
|
this.activeAudioSrc = '';
|
|
this.activeAudioSrc = '';
|
|
|
this.activeAudioStartAt = 0;
|
|
this.activeAudioStartAt = 0;
|
|
@@ -111,6 +337,14 @@ class Home extends React.Component {
|
|
|
|
|
|
|
|
skipCurrentVoice = (reason) => {
|
|
skipCurrentVoice = (reason) => {
|
|
|
console.error(`音频播放失败,跳过当前音频(${reason}): ${this.state.voiceList[0]}`);
|
|
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.activeAudioSrc = '';
|
|
|
this.activeAudioStartAt = 0;
|
|
this.activeAudioStartAt = 0;
|
|
|
this.activeAudioId = '';
|
|
this.activeAudioId = '';
|
|
@@ -150,11 +384,24 @@ class Home extends React.Component {
|
|
|
this.activeAudioId = '';
|
|
this.activeAudioId = '';
|
|
|
this.activeAudioSupportsPlayId = false;
|
|
this.activeAudioSupportsPlayId = false;
|
|
|
this.isAudioBusy = false;
|
|
this.isAudioBusy = false;
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'idle',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ voiceQueueLength: 0,
|
|
|
|
|
+ });
|
|
|
this.setState({ myStatus: false, audioRetryCount: 0 });
|
|
this.setState({ myStatus: false, audioRetryCount: 0 });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (flag === 'success') {
|
|
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.activeAudioSrc = '';
|
|
|
this.activeAudioStartAt = 0;
|
|
this.activeAudioStartAt = 0;
|
|
|
this.activeAudioId = '';
|
|
this.activeAudioId = '';
|
|
@@ -176,6 +423,14 @@ class Home extends React.Component {
|
|
|
// 避免 ON_PAUSE/ON_RESUME 频繁切换导致同一号被 retry 耗尽后丢掉
|
|
// 避免 ON_PAUSE/ON_RESUME 频繁切换导致同一号被 retry 耗尽后丢掉
|
|
|
if (flag === 'paused') {
|
|
if (flag === 'paused') {
|
|
|
console.warn('音频因后台暂停中断,恢复后重新播放当前号');
|
|
console.warn('音频因后台暂停中断,恢复后重新播放当前号');
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'paused',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ voiceQueueLength: this.state.voiceList.length,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ type: 'audio',
|
|
|
|
|
+ message: '播放因后台暂停中断',
|
|
|
|
|
+ });
|
|
|
this.activeAudioSrc = '';
|
|
this.activeAudioSrc = '';
|
|
|
this.activeAudioStartAt = 0;
|
|
this.activeAudioStartAt = 0;
|
|
|
this.activeAudioId = '';
|
|
this.activeAudioId = '';
|
|
@@ -190,6 +445,14 @@ class Home extends React.Component {
|
|
|
const elapsed = Date.now() - this.activeAudioStartAt;
|
|
const elapsed = Date.now() - this.activeAudioStartAt;
|
|
|
if (retryCount <= this.MAX_AUDIO_RETRY && elapsed < this.AUDIO_TOTAL_TIMEOUT_MS) {
|
|
if (retryCount <= this.MAX_AUDIO_RETRY && elapsed < this.AUDIO_TOTAL_TIMEOUT_MS) {
|
|
|
console.warn(`音频播放失败,第 ${retryCount} 次重试: ${this.state.voiceList[0]}`);
|
|
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.setState({ audioRetryCount: retryCount }, () => {
|
|
|
this.soundPaly();
|
|
this.soundPaly();
|
|
|
});
|
|
});
|
|
@@ -210,6 +473,14 @@ class Home extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (status === 'started') {
|
|
if (status === 'started') {
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'started',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ voiceQueueLength: this.state.voiceList.length,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ type: 'audio',
|
|
|
|
|
+ message: `开始播放: ${this.getShortFileName(this.activeAudioSrc)}`,
|
|
|
|
|
+ });
|
|
|
this.clearAudioWatchdog();
|
|
this.clearAudioWatchdog();
|
|
|
this.audioTimeoutId = setTimeout(() => {
|
|
this.audioTimeoutId = setTimeout(() => {
|
|
|
console.error(`音频播放中超时(${this.AUDIO_PLAYING_TIMEOUT_MS}ms),强制跳转: ${this.activeAudioSrc}`);
|
|
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 elapsed = Date.now() - this.activeAudioStartAt;
|
|
|
const remaining = totalTimeoutMs - elapsed;
|
|
const remaining = totalTimeoutMs - elapsed;
|
|
|
if (remaining <= 0) {
|
|
if (remaining <= 0) {
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'timeout',
|
|
|
|
|
+ lastAudioError: 'total-timeout',
|
|
|
|
|
+ voiceQueueLength: this.state.voiceList.length,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ type: 'audio',
|
|
|
|
|
+ message: `音频总时长超时: ${this.getShortFileName(src)}`,
|
|
|
|
|
+ });
|
|
|
this.skipCurrentVoice('timeout');
|
|
this.skipCurrentVoice('timeout');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.isAudioBusy = true;
|
|
this.isAudioBusy = true;
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'starting',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ lastAudioUrl: src,
|
|
|
|
|
+ voiceQueueLength: this.state.voiceList.length,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ type: 'audio',
|
|
|
|
|
+ message: `准备播放: ${this.getShortFileName(src)}`,
|
|
|
|
|
+ });
|
|
|
this.setState(
|
|
this.setState(
|
|
|
{
|
|
{
|
|
|
myStatus: true,
|
|
myStatus: true,
|
|
@@ -276,6 +564,14 @@ class Home extends React.Component {
|
|
|
);
|
|
);
|
|
|
this.audioTimeoutId = setTimeout(() => {
|
|
this.audioTimeoutId = setTimeout(() => {
|
|
|
console.error(`音频启动超时(${timeoutMs}ms),强制跳转: ${src}`);
|
|
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) {
|
|
if (!this.activeAudioSupportsPlayId) {
|
|
|
this.ignoreNextLegacyAudioCallback = true;
|
|
this.ignoreNextLegacyAudioCallback = true;
|
|
|
}
|
|
}
|
|
@@ -293,6 +589,14 @@ class Home extends React.Component {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
console.error(`audio bridge unavailable, skip: ${src}`);
|
|
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');
|
|
this.handleMediaPlayOver('error');
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -303,6 +607,11 @@ class Home extends React.Component {
|
|
|
this.activeAudioId = '';
|
|
this.activeAudioId = '';
|
|
|
this.activeAudioSupportsPlayId = false;
|
|
this.activeAudioSupportsPlayId = false;
|
|
|
this.isAudioBusy = false;
|
|
this.isAudioBusy = false;
|
|
|
|
|
+ this.updateDebugInfo({
|
|
|
|
|
+ lastAudioStatus: 'idle',
|
|
|
|
|
+ lastAudioError: '',
|
|
|
|
|
+ voiceQueueLength: 0,
|
|
|
|
|
+ });
|
|
|
this.setState({
|
|
this.setState({
|
|
|
myStatus: false,
|
|
myStatus: false,
|
|
|
});
|
|
});
|
|
@@ -401,6 +710,35 @@ class Home extends React.Component {
|
|
|
};
|
|
};
|
|
|
handleSocketStatus = (status = {}) => {
|
|
handleSocketStatus = (status = {}) => {
|
|
|
const updatedAt = new Date().toLocaleTimeString('zh-CN', { hour12: false });
|
|
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) => ({
|
|
this.setState((prevState) => ({
|
|
|
socketStatus: {
|
|
socketStatus: {
|
|
|
...prevState.socketStatus,
|
|
...prevState.socketStatus,
|
|
@@ -421,6 +759,10 @@ class Home extends React.Component {
|
|
|
message: '长连接已连接',
|
|
message: '长连接已连接',
|
|
|
lastError: '',
|
|
lastError: '',
|
|
|
});
|
|
});
|
|
|
|
|
+ this.updateDebugInfo(null, {
|
|
|
|
|
+ type: 'socket',
|
|
|
|
|
+ message: '手动重连时 socket 仍显示已连接',
|
|
|
|
|
+ });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
window.socket.connect();
|
|
window.socket.connect();
|
|
@@ -463,10 +805,34 @@ class Home extends React.Component {
|
|
|
obj,
|
|
obj,
|
|
|
(data) => {
|
|
(data) => {
|
|
|
// console.log('Room接收消息:', 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 {
|
|
try {
|
|
|
data = typeof data === 'string' ? JSON.parse(data) : data;
|
|
data = typeof data === 'string' ? JSON.parse(data) : data;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('叫号消息解析失败:', error, data);
|
|
console.error('叫号消息解析失败:', error, data);
|
|
|
|
|
+ this.updateDebugInfo((debugInfo) => ({
|
|
|
|
|
+ parseErrorCount: debugInfo.parseErrorCount + 1,
|
|
|
|
|
+ }), {
|
|
|
|
|
+ type: 'message',
|
|
|
|
|
+ message: '叫号消息 JSON 解析失败',
|
|
|
|
|
+ });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (data.callMsg) {
|
|
if (data.callMsg) {
|
|
@@ -485,6 +851,17 @@ class Home extends React.Component {
|
|
|
const voiceUrl = (data.path && data.voiceFileName)
|
|
const voiceUrl = (data.path && data.voiceFileName)
|
|
|
? String(data.path) + String(data.voiceFileName)
|
|
? String(data.path) + String(data.voiceFileName)
|
|
|
: null;
|
|
: 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(
|
|
this.setState(
|
|
|
(prevState) => {
|
|
(prevState) => {
|
|
|
// 使用 prevState 保证高并发消息下不丢更新(避免覆盖前一条 roomObjtmp)
|
|
// 使用 prevState 保证高并发消息下不丢更新(避免覆盖前一条 roomObjtmp)
|
|
@@ -502,6 +879,26 @@ class Home extends React.Component {
|
|
|
nextVoiceList = nextVoiceList.slice(dropCount);
|
|
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 {
|
|
return {
|
|
|
userData: {
|
|
userData: {
|
|
|
...data?.userData,
|
|
...data?.userData,
|
|
@@ -518,6 +915,7 @@ class Home extends React.Component {
|
|
|
roomObjtmp,
|
|
roomObjtmp,
|
|
|
patListArea: newArray,
|
|
patListArea: newArray,
|
|
|
voiceList: nextVoiceList,
|
|
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,
|
|
this.handleSocketStatus,
|
|
@@ -640,6 +1045,33 @@ class Home extends React.Component {
|
|
|
</div>
|
|
</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' ? (
|
|
{this.state.showType == 'doctor' ? (
|
|
|
<DoctorScreen
|
|
<DoctorScreen
|
|
|
userData={this.state.userData}
|
|
userData={this.state.userData}
|
|
@@ -682,6 +1114,16 @@ class Home extends React.Component {
|
|
|
{this.state?.updateTime || ''}
|
|
{this.state?.updateTime || ''}
|
|
|
</span>
|
|
</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
|
|
<AntOutline
|
|
|
style={{
|
|
style={{
|
|
|
color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
|
|
color: this.state.colorName == 'dark-bg' ? '#fff' : '#0D2764',
|