api: implement first server API + tests

This commit is contained in:
Mathieu Virbel
2023-08-04 18:16:37 +02:00
parent 20767fde3f
commit 96f52c631a
8 changed files with 327 additions and 23 deletions

View File

@@ -3,7 +3,6 @@ import time
import uuid
import httpx
import pyaudio
import stamina
from aiortc import RTCPeerConnection, RTCSessionDescription
from aiortc.contrib.media import MediaPlayer, MediaRelay
@@ -24,7 +23,6 @@ class StreamClient:
self.server_url = url
self.play_from = play_from
self.ping_pong = ping_pong
self.paudio = pyaudio.PyAudio()
self.pc = RTCPeerConnection()
@@ -87,6 +85,7 @@ class StreamClient:
self.logger.info(f"Track {track.kind} ended")
self.pc.addTrack(audio)
self.track_audio = audio
channel = pc.createDataChannel("data-channel")
self.logger = self.logger.bind(channel=channel.label)
@@ -142,3 +141,6 @@ class StreamClient:
coro = self.run_offer(self.pc, self.signaling)
task = asyncio.create_task(coro)
await task
def is_ended(self):
return self.track_audio is None or self.track_audio.readyState == "ended"