-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
70 lines (51 loc) · 1.54 KB
/
server.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
TODO: Update here once changed things around
"""
import argparse
import asyncio
from aiortc import RTCPeerConnection
from aiortc.contrib.signaling import add_signaling_arguments, create_signaling
from rtc_signal_handlers import consume_signaling
from video_track import WebCamTrack
async def run_server(pc, signaling):
"""
Main function that initializes the server and handles the signaling process.
Args:
pc (RTCPeerConnection): The RTCPeerConnection object.
signaling (Signaling): The signaling object.
Returns:
None
"""
await signaling.connect()
pc.addTrack(WebCamTrack())
# Create an offer
offer = await pc.createOffer()
await pc.setLocalDescription(offer)
print("Created offer")
# Send the offer to the signaling server
await signaling.send(pc.localDescription)
print("Sent offer to signaling server")
await consume_signaling(pc, signaling)
def main():
"""
Entry point of the program.
Args:
None
Returns:
None
"""
parser = argparse.ArgumentParser(description="Server for the face detection system")
add_signaling_arguments(parser)
args = parser.parse_args()
signaling = create_signaling(args)
pc = RTCPeerConnection()
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run_server(pc, signaling))
except KeyboardInterrupt:
pass
finally:
loop.run_until_complete(pc.close())
loop.run_until_complete(signaling.close())
if __name__ == "__main__":
main()