Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import string
|
|
| 7 |
import time
|
| 8 |
import logging
|
| 9 |
import uuid
|
| 10 |
-
import json
|
| 11 |
|
| 12 |
# 配置日志
|
| 13 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
@@ -19,11 +18,9 @@ app.config['SECRET_KEY'] = os.urandom(24)
|
|
| 19 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
| 20 |
|
| 21 |
# 存储活跃会议信息
|
| 22 |
-
# 格式: {'meeting_id': {'host': 'user_id', 'participants': {user_id: {name, role, joined_at}}, 'created_at': timestamp}}
|
| 23 |
active_meetings = {}
|
| 24 |
|
| 25 |
# 存储用户连接信息
|
| 26 |
-
# 格式: {sid: {'user_id': user_id, 'meeting_id': meeting_id}}
|
| 27 |
connected_users = {}
|
| 28 |
|
| 29 |
def generate_meeting_id():
|
|
@@ -34,20 +31,9 @@ def format_meeting_id(meeting_id):
|
|
| 34 |
"""格式化会议ID为 xxx-xxx-xxx 格式"""
|
| 35 |
return f"{meeting_id[:3]}-{meeting_id[3:6]}-{meeting_id[6:]}"
|
| 36 |
|
| 37 |
-
# 确保
|
| 38 |
os.makedirs(os.path.join(os.path.dirname(__file__), 'static'), exist_ok=True)
|
| 39 |
-
|
| 40 |
-
# 创建HTML文件目录
|
| 41 |
-
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
|
| 42 |
-
os.makedirs(templates_dir, exist_ok=True)
|
| 43 |
-
|
| 44 |
-
# 保存前端HTML到文件
|
| 45 |
-
@app.route('/save_html', methods=['POST'])
|
| 46 |
-
def save_html():
|
| 47 |
-
html_content = request.json.get('html', '')
|
| 48 |
-
with open(os.path.join(templates_dir, 'index.html'), 'w', encoding='utf-8') as f:
|
| 49 |
-
f.write(html_content)
|
| 50 |
-
return jsonify({'success': True})
|
| 51 |
|
| 52 |
# 主页路由
|
| 53 |
@app.route('/')
|
|
@@ -213,41 +199,6 @@ def end_meeting():
|
|
| 213 |
'duration': duration
|
| 214 |
})
|
| 215 |
|
| 216 |
-
# 更新会议设置
|
| 217 |
-
@app.route('/api/update_settings', methods=['POST'])
|
| 218 |
-
def update_settings():
|
| 219 |
-
"""更新会议设置(仅主持人可操作)"""
|
| 220 |
-
user_id = session.get('user_id')
|
| 221 |
-
meeting_id = session.get('meeting_id')
|
| 222 |
-
settings = request.json.get('settings', {})
|
| 223 |
-
|
| 224 |
-
if not meeting_id or meeting_id not in active_meetings:
|
| 225 |
-
return jsonify({
|
| 226 |
-
'success': False,
|
| 227 |
-
'message': '会议不存在或已结束'
|
| 228 |
-
})
|
| 229 |
-
|
| 230 |
-
# 验证是否为主持人
|
| 231 |
-
if active_meetings[meeting_id]['host'] != user_id:
|
| 232 |
-
return jsonify({
|
| 233 |
-
'success': False,
|
| 234 |
-
'message': '只有主持人可以更改会议设置'
|
| 235 |
-
})
|
| 236 |
-
|
| 237 |
-
# 更新设置
|
| 238 |
-
active_meetings[meeting_id]['settings'].update(settings)
|
| 239 |
-
|
| 240 |
-
# 通知所有参会者设置已更新
|
| 241 |
-
socketio.emit('settings_updated', {
|
| 242 |
-
'settings': active_meetings[meeting_id]['settings']
|
| 243 |
-
}, room=meeting_id)
|
| 244 |
-
|
| 245 |
-
return jsonify({
|
| 246 |
-
'success': True,
|
| 247 |
-
'message': '会议设置已更新',
|
| 248 |
-
'settings': active_meetings[meeting_id]['settings']
|
| 249 |
-
})
|
| 250 |
-
|
| 251 |
# 会议视图路由
|
| 252 |
@app.route('/meeting/<meeting_id>')
|
| 253 |
def meeting_room(meeting_id):
|
|
@@ -448,189 +399,6 @@ def handle_media_status(data):
|
|
| 448 |
|
| 449 |
# 主函数
|
| 450 |
if __name__ == '__main__':
|
| 451 |
-
# 确保存在 index.html
|
| 452 |
-
if not os.path.exists(os.path.join(templates_dir, 'index.html')):
|
| 453 |
-
with open(os.path.join(templates_dir, 'index.html'), 'w', encoding='utf-8') as f:
|
| 454 |
-
f.write("""
|
| 455 |
-
<!DOCTYPE html>
|
| 456 |
-
<html lang="zh-CN">
|
| 457 |
-
<head>
|
| 458 |
-
<meta charset="UTF-8">
|
| 459 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 460 |
-
<title>视频会议系统</title>
|
| 461 |
-
<style>
|
| 462 |
-
body {
|
| 463 |
-
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
|
| 464 |
-
background-color: #f5f5f7;
|
| 465 |
-
margin: 0;
|
| 466 |
-
padding: 0;
|
| 467 |
-
display: flex;
|
| 468 |
-
justify-content: center;
|
| 469 |
-
align-items: center;
|
| 470 |
-
height: 100vh;
|
| 471 |
-
color: #1d1d1f;
|
| 472 |
-
}
|
| 473 |
-
.login-container {
|
| 474 |
-
background-color: white;
|
| 475 |
-
padding: 40px;
|
| 476 |
-
border-radius: 16px;
|
| 477 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
| 478 |
-
width: 100%;
|
| 479 |
-
max-width: 400px;
|
| 480 |
-
text-align: center;
|
| 481 |
-
}
|
| 482 |
-
h1 {
|
| 483 |
-
margin-bottom: 30px;
|
| 484 |
-
font-weight: 600;
|
| 485 |
-
}
|
| 486 |
-
.form-group {
|
| 487 |
-
margin-bottom: 20px;
|
| 488 |
-
text-align: left;
|
| 489 |
-
}
|
| 490 |
-
label {
|
| 491 |
-
display: block;
|
| 492 |
-
margin-bottom: 8px;
|
| 493 |
-
font-size: 14px;
|
| 494 |
-
color: #6e6e73;
|
| 495 |
-
}
|
| 496 |
-
input {
|
| 497 |
-
width: 100%;
|
| 498 |
-
padding: 12px;
|
| 499 |
-
border-radius: 8px;
|
| 500 |
-
border: 1px solid #d2d2d7;
|
| 501 |
-
font-size: 16px;
|
| 502 |
-
box-sizing: border-box;
|
| 503 |
-
}
|
| 504 |
-
input:focus {
|
| 505 |
-
outline: none;
|
| 506 |
-
border-color: #0071e3;
|
| 507 |
-
box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.2);
|
| 508 |
-
}
|
| 509 |
-
.buttons {
|
| 510 |
-
display: flex;
|
| 511 |
-
gap: 12px;
|
| 512 |
-
margin-top: 30px;
|
| 513 |
-
}
|
| 514 |
-
button {
|
| 515 |
-
flex: 1;
|
| 516 |
-
background-color: #0071e3;
|
| 517 |
-
color: white;
|
| 518 |
-
border: none;
|
| 519 |
-
padding: 12px 20px;
|
| 520 |
-
border-radius: 8px;
|
| 521 |
-
font-size: 16px;
|
| 522 |
-
cursor: pointer;
|
| 523 |
-
transition: background-color 0.2s;
|
| 524 |
-
}
|
| 525 |
-
button:hover {
|
| 526 |
-
background-color: #0077ed;
|
| 527 |
-
}
|
| 528 |
-
button.secondary {
|
| 529 |
-
background-color: #f5f5f7;
|
| 530 |
-
color: #0071e3;
|
| 531 |
-
}
|
| 532 |
-
button.secondary:hover {
|
| 533 |
-
background-color: #e5e5ea;
|
| 534 |
-
}
|
| 535 |
-
</style>
|
| 536 |
-
</head>
|
| 537 |
-
<body>
|
| 538 |
-
<div class="login-container">
|
| 539 |
-
<h1>视频会议系统</h1>
|
| 540 |
-
<div class="form-group">
|
| 541 |
-
<label for="username">您的姓名</label>
|
| 542 |
-
<input type="text" id="username" placeholder="请输入您的姓名">
|
| 543 |
-
</div>
|
| 544 |
-
<div class="form-group">
|
| 545 |
-
<label for="meeting-id">会议号(新建会议可留空)</label>
|
| 546 |
-
<input type="text" id="meeting-id" placeholder="例如: 123-456-789">
|
| 547 |
-
</div>
|
| 548 |
-
<div class="buttons">
|
| 549 |
-
<button id="create-meeting" class="secondary">新建会议</button>
|
| 550 |
-
<button id="join-meeting">加入会议</button>
|
| 551 |
-
</div>
|
| 552 |
-
</div>
|
| 553 |
-
|
| 554 |
-
<script>
|
| 555 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 556 |
-
const createMeetingBtn = document.getElementById('create-meeting');
|
| 557 |
-
const joinMeetingBtn = document.getElementById('join-meeting');
|
| 558 |
-
const usernameInput = document.getElementById('username');
|
| 559 |
-
const meetingIdInput = document.getElementById('meeting-id');
|
| 560 |
-
|
| 561 |
-
// 创建会议
|
| 562 |
-
createMeetingBtn.addEventListener('click', function() {
|
| 563 |
-
const username = usernameInput.value.trim();
|
| 564 |
-
if (!username) {
|
| 565 |
-
alert('请输入您的姓名');
|
| 566 |
-
return;
|
| 567 |
-
}
|
| 568 |
-
|
| 569 |
-
fetch('/api/create_meeting', {
|
| 570 |
-
method: 'POST',
|
| 571 |
-
headers: {
|
| 572 |
-
'Content-Type': 'application/json',
|
| 573 |
-
},
|
| 574 |
-
body: JSON.stringify({
|
| 575 |
-
user_name: username
|
| 576 |
-
}),
|
| 577 |
-
})
|
| 578 |
-
.then(response => response.json())
|
| 579 |
-
.then(data => {
|
| 580 |
-
if (data.success) {
|
| 581 |
-
window.location.href = `/meeting/${data.meeting_id}`;
|
| 582 |
-
} else {
|
| 583 |
-
alert(data.message || '创建会议失败');
|
| 584 |
-
}
|
| 585 |
-
})
|
| 586 |
-
.catch(error => {
|
| 587 |
-
console.error('Error:', error);
|
| 588 |
-
alert('创建会议失败,请重试');
|
| 589 |
-
});
|
| 590 |
-
});
|
| 591 |
-
|
| 592 |
-
// 加入会议
|
| 593 |
-
joinMeetingBtn.addEventListener('click', function() {
|
| 594 |
-
const username = usernameInput.value.trim();
|
| 595 |
-
const meetingId = meetingIdInput.value.trim();
|
| 596 |
-
if (!username) {
|
| 597 |
-
alert('请输入您的姓名');
|
| 598 |
-
return;
|
| 599 |
-
}
|
| 600 |
-
if (!meetingId) {
|
| 601 |
-
alert('请输入会议号');
|
| 602 |
-
return;
|
| 603 |
-
}
|
| 604 |
-
|
| 605 |
-
fetch('/api/join_meeting', {
|
| 606 |
-
method: 'POST',
|
| 607 |
-
headers: {
|
| 608 |
-
'Content-Type': 'application/json',
|
| 609 |
-
},
|
| 610 |
-
body: JSON.stringify({
|
| 611 |
-
user_name: username,
|
| 612 |
-
meeting_id: meetingId
|
| 613 |
-
}),
|
| 614 |
-
})
|
| 615 |
-
.then(response => response.json())
|
| 616 |
-
.then(data => {
|
| 617 |
-
if (data.success) {
|
| 618 |
-
window.location.href = `/meeting/${data.meeting_id}`;
|
| 619 |
-
} else {
|
| 620 |
-
alert(data.message || '加入会议失败');
|
| 621 |
-
}
|
| 622 |
-
})
|
| 623 |
-
.catch(error => {
|
| 624 |
-
console.error('Error:', error);
|
| 625 |
-
alert('加入会议失败,请重试');
|
| 626 |
-
});
|
| 627 |
-
});
|
| 628 |
-
});
|
| 629 |
-
</script>
|
| 630 |
-
</body>
|
| 631 |
-
</html>
|
| 632 |
-
""")
|
| 633 |
-
|
| 634 |
# 启动服务器
|
| 635 |
logger.info("视频会议系统服务器启动中...")
|
| 636 |
socketio.run(app, host='0.0.0.0', port=7860, debug=True, allow_unsafe_werkzeug=True)
|
|
|
|
| 7 |
import time
|
| 8 |
import logging
|
| 9 |
import uuid
|
|
|
|
| 10 |
|
| 11 |
# 配置日志
|
| 12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
| 18 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
| 19 |
|
| 20 |
# 存储活跃会议信息
|
|
|
|
| 21 |
active_meetings = {}
|
| 22 |
|
| 23 |
# 存储用户连接信息
|
|
|
|
| 24 |
connected_users = {}
|
| 25 |
|
| 26 |
def generate_meeting_id():
|
|
|
|
| 31 |
"""格式化会议ID为 xxx-xxx-xxx 格式"""
|
| 32 |
return f"{meeting_id[:3]}-{meeting_id[3:6]}-{meeting_id[6:]}"
|
| 33 |
|
| 34 |
+
# 确保目录结构存在
|
| 35 |
os.makedirs(os.path.join(os.path.dirname(__file__), 'static'), exist_ok=True)
|
| 36 |
+
os.makedirs(os.path.join(os.path.dirname(__file__), 'templates'), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# 主页路由
|
| 39 |
@app.route('/')
|
|
|
|
| 199 |
'duration': duration
|
| 200 |
})
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
# 会议视图路由
|
| 203 |
@app.route('/meeting/<meeting_id>')
|
| 204 |
def meeting_room(meeting_id):
|
|
|
|
| 399 |
|
| 400 |
# 主函数
|
| 401 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
# 启动服务器
|
| 403 |
logger.info("视频会议系统服务器启动中...")
|
| 404 |
socketio.run(app, host='0.0.0.0', port=7860, debug=True, allow_unsafe_werkzeug=True)
|