30 lines
755 B
Python
30 lines
755 B
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import json
|
|
|
|
import websockets
|
|
from loguru import logger
|
|
|
|
from app.webrtc.peer_session import PeerSession
|
|
from configs.load import config
|
|
|
|
|
|
async def handle_client(websocket):
|
|
"""处理单个WebSocket客户端连接"""
|
|
client = websocket.remote_address
|
|
logger.info(f"Client connected: {client}")
|
|
|
|
session = PeerSession()
|
|
await session.handle(websocket)
|
|
|
|
logger.info(f"Connection closed: {client}")
|
|
|
|
|
|
async def main():
|
|
"""启动WebSocket信令服务器"""
|
|
cfg = config.server
|
|
logger.info(f"WebRTC signaling server: ws://{cfg.host}:{cfg.port}")
|
|
async with websockets.serve(handle_client, cfg.host, cfg.port, max_size=cfg.max_ws_size):
|
|
await asyncio.Future()
|