-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (24 loc) · 964 Bytes
/
server.py
File metadata and controls
35 lines (24 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from aiohttp import web
from aiortc import RTCPeerConnection, RTCSessionDescription
from track import Track, SharedVideoSource
# Create a shared video source
video_source = SharedVideoSource(width=640, height=480)
async def index(request):
return web.FileResponse("index.html")
async def offer(request: web.Request):
params = await request.json()
offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])
pc = RTCPeerConnection()
video_track = Track(video_source)
pc.addTrack(video_track)
# Set remote description and create an answer
await pc.setRemoteDescription(offer)
answer = await pc.createAnswer()
await pc.setLocalDescription(answer)
return web.json_response(
{"sdp": pc.localDescription.sdp, "type": pc.localDescription.type}
)
app = web.Application()
app.add_routes([web.post("/offer", offer), web.get("/", index)])
if __name__ == "__main__":
web.run_app(app, port=8080)