-
Notifications
You must be signed in to change notification settings - Fork 1
/
client copy.py
56 lines (38 loc) · 1.23 KB
/
client copy.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
from aiortc.contrib.signaling import TcpSocketSignaling
from aiortc.contrib.media import MediaRecorder
from aiortc import RTCPeerConnection, RTCSessionDescription
import asyncio
import socket
import cv2
PORT = 5000
SERVER = socket.gethostbyname(socket.gethostname())
async def run(signaling, pc, recorder):
@pc.on("track")
def on_track(track):
print("Receiving %s" % track.kind)
print(track)
recorder.addTrack(track)
# receive the offer from server
await signaling.connect()
print('connected')
# while True:
desc = await signaling.receive()
# if isinstance(desc, RTCSessionDescription):
await pc.setRemoteDescription(desc)
print('offer received: ')
#print(desc)
answer = await pc.createAnswer()
await signaling.send(answer)
print("answer sent")
#await recorder.start()
# create an aiortc answer and send
# await pc.setLocalDescription(await pc.createAnswer())
# await signaling.send(pc.localDescription)
await signaling.close()
signaling = TcpSocketSignaling(SERVER, PORT)
pc = RTCPeerConnection()
recorder = MediaRecorder("/recordedimg/img-%3d.png")
coro = run(signaling, pc, recorder)
asyncio.run(coro)
# RTCRtpReceiver
# create data channel