Twilioapp/test-status.html
2025-06-29 01:33:41 +08:00

263 lines
9.5 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twilio 视频通话服务状态检查</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.status-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
margin: 10px 0;
border-radius: 8px;
background-color: #f8f9fa;
}
.status-label {
font-weight: 500;
color: #495057;
}
.status-indicator {
padding: 5px 15px;
border-radius: 20px;
font-size: 14px;
font-weight: 500;
}
.status-success {
background-color: #d4edda;
color: #155724;
}
.status-error {
background-color: #f8d7da;
color: #721c24;
}
.status-pending {
background-color: #fff3cd;
color: #856404;
}
.test-button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin-left: 10px;
}
.test-button:hover {
background-color: #0056b3;
}
.test-button:disabled {
background-color: #6c757d;
cursor: not-allowed;
}
.info-section {
margin-top: 30px;
padding: 20px;
background-color: #e9ecef;
border-radius: 8px;
}
.info-section h3 {
margin-top: 0;
color: #495057;
}
.info-section ul {
margin: 10px 0;
padding-left: 20px;
}
.info-section li {
margin: 5px 0;
}
.quick-links {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 20px;
}
.quick-link {
display: block;
padding: 15px;
background-color: #007bff;
color: white;
text-decoration: none;
border-radius: 8px;
text-align: center;
font-weight: 500;
transition: background-color 0.2s;
}
.quick-link:hover {
background-color: #0056b3;
color: white;
}
</style>
</head>
<body>
<div class="container">
<h1>🎥 Twilio 视频通话服务状态</h1>
<div class="status-item">
<span class="status-label">后端 Token 服务器 (localhost:3001)</span>
<div>
<span id="backend-status" class="status-indicator status-pending">检查中...</span>
<button class="test-button" onclick="checkBackend()">重新检查</button>
</div>
</div>
<div class="status-item">
<span class="status-label">前端应用 (localhost:5173)</span>
<div>
<span id="frontend-status" class="status-indicator status-pending">检查中...</span>
<button class="test-button" onclick="checkFrontend()">重新检查</button>
</div>
</div>
<div class="status-item">
<span class="status-label">摄像头权限</span>
<div>
<span id="camera-status" class="status-indicator status-pending">未检查</span>
<button class="test-button" onclick="checkCamera()">检查权限</button>
</div>
</div>
<div class="status-item">
<span class="status-label">麦克风权限</span>
<div>
<span id="microphone-status" class="status-indicator status-pending">未检查</span>
<button class="test-button" onclick="checkMicrophone()">检查权限</button>
</div>
</div>
<div class="info-section">
<h3>📋 快速测试指南</h3>
<ul>
<li><strong>步骤 1:</strong> 确保所有服务状态显示为"正常"</li>
<li><strong>步骤 2:</strong> 点击"检查权限"按钮允许摄像头和麦克风访问</li>
<li><strong>步骤 3:</strong> 使用下方的快速链接访问测试页面</li>
<li><strong>步骤 4:</strong> 在两个不同的浏览器标签页中测试多人通话</li>
</ul>
</div>
<div class="quick-links">
<a href="http://localhost:5173" class="quick-link">🏠 主应用</a>
<a href="http://localhost:5173/device-test" class="quick-link">🔧 设备测试</a>
<a href="http://localhost:5173/video-call" class="quick-link">📹 视频通话</a>
<a href="http://localhost:3001/health" class="quick-link">💚 服务器状态</a>
</div>
<div class="info-section">
<h3>⚠️ 注意事项</h3>
<ul>
<li>确保在 <code>server/index.js</code> 中配置了正确的 Twilio 凭证</li>
<li>建议使用 Chrome 浏览器进行测试</li>
<li>如果遇到 CORS 错误,请检查服务器配置</li>
<li>生产环境需要 HTTPS 才能访问摄像头和麦克风</li>
</ul>
</div>
</div>
<script>
// 检查后端服务器状态
async function checkBackend() {
const statusElement = document.getElementById('backend-status');
statusElement.textContent = '检查中...';
statusElement.className = 'status-indicator status-pending';
try {
const response = await fetch('http://localhost:3001/health');
if (response.ok) {
const data = await response.json();
statusElement.textContent = '正常';
statusElement.className = 'status-indicator status-success';
} else {
throw new Error('服务器响应错误');
}
} catch (error) {
statusElement.textContent = '无法连接';
statusElement.className = 'status-indicator status-error';
}
}
// 检查前端应用状态
async function checkFrontend() {
const statusElement = document.getElementById('frontend-status');
statusElement.textContent = '检查中...';
statusElement.className = 'status-indicator status-pending';
try {
const response = await fetch('http://localhost:5173');
if (response.ok) {
statusElement.textContent = '正常';
statusElement.className = 'status-indicator status-success';
} else {
throw new Error('前端应用响应错误');
}
} catch (error) {
statusElement.textContent = '无法连接';
statusElement.className = 'status-indicator status-error';
}
}
// 检查摄像头权限
async function checkCamera() {
const statusElement = document.getElementById('camera-status');
statusElement.textContent = '检查中...';
statusElement.className = 'status-indicator status-pending';
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
stream.getTracks().forEach(track => track.stop());
statusElement.textContent = '已授权';
statusElement.className = 'status-indicator status-success';
} catch (error) {
statusElement.textContent = '权限被拒绝';
statusElement.className = 'status-indicator status-error';
}
}
// 检查麦克风权限
async function checkMicrophone() {
const statusElement = document.getElementById('microphone-status');
statusElement.textContent = '检查中...';
statusElement.className = 'status-indicator status-pending';
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stream.getTracks().forEach(track => track.stop());
statusElement.textContent = '已授权';
statusElement.className = 'status-indicator status-success';
} catch (error) {
statusElement.textContent = '权限被拒绝';
statusElement.className = 'status-indicator status-error';
}
}
// 页面加载时自动检查服务状态
window.addEventListener('load', () => {
setTimeout(() => {
checkBackend();
checkFrontend();
}, 1000);
});
</script>
</body>
</html>