Spaces:
Sleeping
Sleeping
Commit ·
7d6af92
1
Parent(s): 417b750
更新
Browse files
static/frontend/js/websocket.js
CHANGED
|
@@ -747,8 +747,16 @@ function initializeWebSocket(token) {
|
|
| 747 |
case 'error':
|
| 748 |
// 錯誤訊息
|
| 749 |
console.error('❌ 後端錯誤:', data.message);
|
| 750 |
-
|
| 751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
break;
|
| 753 |
|
| 754 |
case 'voice_login_result':
|
|
@@ -777,6 +785,14 @@ function initializeWebSocket(token) {
|
|
| 777 |
console.log('✅ 語音綁定完成(已更新本地狀態)');
|
| 778 |
break;
|
| 779 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
default:
|
| 781 |
console.log('🔍 未處理的訊息類型:', data.type);
|
| 782 |
}
|
|
|
|
| 747 |
case 'error':
|
| 748 |
// 錯誤訊息
|
| 749 |
console.error('❌ 後端錯誤:', data.message);
|
| 750 |
+
|
| 751 |
+
const messageText = data && typeof data.message === 'string' ? data.message : '';
|
| 752 |
+
const isEnvSnapshotWarning = messageText.includes('env_snapshot');
|
| 753 |
+
|
| 754 |
+
if (!isEnvSnapshotWarning) {
|
| 755 |
+
setState('idle');
|
| 756 |
+
showErrorNotification(messageText || '系統發生未知錯誤');
|
| 757 |
+
} else {
|
| 758 |
+
console.warn('⚠️ 後端尚未支援 env_snapshot,忽略此警告');
|
| 759 |
+
}
|
| 760 |
break;
|
| 761 |
|
| 762 |
case 'voice_login_result':
|
|
|
|
| 785 |
console.log('✅ 語音綁定完成(已更新本地狀態)');
|
| 786 |
break;
|
| 787 |
|
| 788 |
+
case 'env_ack':
|
| 789 |
+
if (data.success) {
|
| 790 |
+
console.log('🧭 環境快照已同步,Geohash:', data.geohash_7, 'Heading:', data.heading);
|
| 791 |
+
} else {
|
| 792 |
+
console.warn('⚠️ 環境快照同步失敗:', data.error);
|
| 793 |
+
}
|
| 794 |
+
break;
|
| 795 |
+
|
| 796 |
default:
|
| 797 |
console.log('🔍 未處理的訊息類型:', data.type);
|
| 798 |
}
|
tests/frontend/test_websocket_syntax.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_websocket_js_has_no_syntax_errors():
|
| 7 |
+
root = Path(__file__).resolve().parents[2]
|
| 8 |
+
js_path = root / "static" / "frontend" / "js" / "websocket.js"
|
| 9 |
+
|
| 10 |
+
result = subprocess.run(
|
| 11 |
+
["node", "--check", str(js_path)],
|
| 12 |
+
capture_output=True,
|
| 13 |
+
text=True,
|
| 14 |
+
env=os.environ,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
assert result.returncode == 0, (
|
| 18 |
+
f"websocket.js has syntax errors: {result.stderr.strip() or result.stdout.strip()}"
|
| 19 |
+
)
|