Add more logging. Logging is good.

This commit is contained in:
Marks Polakovs 2020-04-03 09:56:52 +02:00
parent fefed06a5f
commit 9b79e1721f

View file

@ -71,6 +71,7 @@ class Session(object):
self.pc = None self.pc = None
async def end(): async def end():
print(self.connection_id, "going away")
if self.sender is not None: if self.sender is not None:
self.sender.end() self.sender.end()
await self.pc.close() await self.pc.close()
@ -79,25 +80,25 @@ class Session(object):
async def connect(self, websocket): async def connect(self, websocket):
self.websocket = websocket self.websocket = websocket
connection_id = uuid.uuid4(); self.connection_id = uuid.uuid4();
print(connection_id, "Connected") print(self.connection_id, "Connected")
await websocket.send(json.dumps({"kind": "HELLO", "connectionId": str(connection_id)})) await websocket.send(json.dumps({"kind": "HELLO", "connectionId": str(self.connection_id)}))
sdp_offer = json.loads(await websocket.recv()) sdp_offer = json.loads(await websocket.recv())
if sdp_offer["kind"] != "OFFER": if sdp_offer["kind"] != "OFFER":
await websocket.close(1008) await websocket.close(1008)
return return
offer = RTCSessionDescription(sdp=sdp_offer["sdp"], type=sdp_offer["type"]) offer = RTCSessionDescription(sdp=sdp_offer["sdp"], type=sdp_offer["type"])
print(connection_id, "Received offer") print(self.connection_id, "Received offer")
self.pc = RTCPeerConnection() self.pc = RTCPeerConnection()
@self.pc.on("signalingstatechange") @self.pc.on("signalingstatechange")
async def on_signalingstatechange(): async def on_signalingstatechange():
print(connection_id, "Signaling state is {}".format(self.pc.signalingState)) print(self.connection_id, "Signaling state is {}".format(self.pc.signalingState))
@self.pc.on("iceconnectionstatechange") @self.pc.on("iceconnectionstatechange")
async def on_iceconnectionstatechange(): async def on_iceconnectionstatechange():
print(connection_id, "ICE connection state is {}".format(self.pc.iceConnectionState)) print(self.connection_id, "ICE connection state is {}".format(self.pc.iceConnectionState))
if self.pc.iceConnectionState == "failed": if self.pc.iceConnectionState == "failed":
await self.pc.close() await self.pc.close()
self.pc = None self.pc = None
@ -107,13 +108,13 @@ class Session(object):
@self.pc.on("track") @self.pc.on("track")
async def on_track(track): async def on_track(track):
global current_session global current_session
print(connection_id, "Received track") print(self.connection_id, "Received track")
if track.kind == "audio": if track.kind == "audio":
print(connection_id, "Adding to Jack.") print(self.connection_id, "Adding to Jack.")
@track.on("ended") @track.on("ended")
async def on_ended(): async def on_ended():
print(connection_id, "Track {} ended".format(track.kind)) print(self.connection_id, "Track {} ended".format(track.kind))
init_buffers() init_buffers()
self.sender = JackSender(track) self.sender = JackSender(track)
@ -137,10 +138,10 @@ class Session(object):
} }
) )
) )
print(connection_id, "Sent answer") print(self.connection_id, "Sent answer")
async for msg in websocket: async for msg in websocket:
print(connection_id, msg) print(self.connection_id, msg)
async def serve(websocket, path): async def serve(websocket, path):
@ -151,8 +152,12 @@ async def serve(websocket, path):
pass pass
WS_PORT = 8079
jack.activate() jack.activate()
start_server = websockets.serve(serve, "localhost", 8079) start_server = websockets.serve(serve, "localhost", WS_PORT)
print("Shittyserver starting on port {}.".format(WS_PORT))
asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever() asyncio.get_event_loop().run_forever()