added a small API to see the peer status
This commit is contained in:
parent
a5e4830acb
commit
ab745aa75a
4 changed files with 35 additions and 0 deletions
|
@ -18,3 +18,7 @@ sounddevice~=0.5.1
|
|||
|
||||
# system
|
||||
pyudev~=0.24.3
|
||||
|
||||
# api
|
||||
fastapi
|
||||
uvicorn
|
23
source/managers/ApiManager.py
Normal file
23
source/managers/ApiManager.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import fastapi
|
||||
import uvicorn
|
||||
|
||||
|
||||
class ApiManager:
|
||||
"""
|
||||
Manage the API to have a representation of the device connection
|
||||
"""
|
||||
|
||||
def __init__(self, manager: "Manager"):
|
||||
self.manager = manager
|
||||
|
||||
self.application = fastapi.FastAPI()
|
||||
|
||||
@self.application.get("/peers")
|
||||
async def peers():
|
||||
return {
|
||||
address
|
||||
for address, peer in self.manager.peer.peers.items()
|
||||
}
|
||||
|
||||
def loop(self):
|
||||
uvicorn.run(self.application)
|
|
@ -3,6 +3,7 @@ from pathlib import Path
|
|||
|
||||
from source import packets
|
||||
from source.behaviors import events
|
||||
from source.managers.ApiManager import ApiManager
|
||||
|
||||
|
||||
class Manager:
|
||||
|
@ -44,6 +45,9 @@ class Manager:
|
|||
# drive manager
|
||||
self.drive = DriveManager(self)
|
||||
|
||||
# api manager
|
||||
self.api = ApiManager(self)
|
||||
|
||||
def loop(self) -> None:
|
||||
"""
|
||||
Handle the sub-managers forever
|
||||
|
@ -55,15 +59,18 @@ class Manager:
|
|||
audio_thread = threading.Thread(target=self.audio.loop)
|
||||
peer_thread = threading.Thread(target=self.peer.loop)
|
||||
drive_thread = threading.Thread(target=self.drive.loop)
|
||||
api_thread = threading.Thread(target=self.api.loop)
|
||||
|
||||
event_thread.start()
|
||||
role_thread.start()
|
||||
audio_thread.start()
|
||||
peer_thread.start()
|
||||
drive_thread.start()
|
||||
api_thread.start()
|
||||
|
||||
event_thread.join()
|
||||
role_thread.join()
|
||||
audio_thread.join()
|
||||
peer_thread.join()
|
||||
drive_thread.join()
|
||||
api_thread.join()
|
||||
|
|
|
@ -4,5 +4,6 @@ from .RoleManager import RoleManager
|
|||
from .AudioManager import AudioManager
|
||||
from .PeerManager import PeerManager
|
||||
from .DriveManager import DriveManager
|
||||
from .ApiManager import ApiManager
|
||||
|
||||
from .Manager import Manager
|
||||
|
|
Loading…
Reference in a new issue