7
7
from collections import OrderedDict
8
8
from typing import List
9
9
10
- import aiohttp
11
10
import openai
12
- from livekit import agents , api , protocol , rtc
11
+ from livekit import agents , api , rtc
13
12
14
13
from drawings import Line , PlayerDrawing
15
14
from prompts import PROMPTS , DifficultyLevel
@@ -65,6 +64,7 @@ def __init__(self, ctx: agents.JobContext):
65
64
self ._ctx = ctx
66
65
self ._game_state = GameState ()
67
66
self ._openai_client = openai .AsyncOpenAI ()
67
+ self ._lkapi = api .LiveKitAPI ()
68
68
self ._drawings = {}
69
69
self ._guess_cache = GuessCache ()
70
70
self ._last_guesses = {}
@@ -74,6 +74,7 @@ def __init__(self, ctx: agents.JobContext):
74
74
async def connect (self ):
75
75
print ("Starting game host agent" )
76
76
await self ._ctx .connect ()
77
+
77
78
for participant in self ._ctx .room .remote_participants .values ():
78
79
if self ._register_player (participant ):
79
80
await self ._load_player_drawing (participant )
@@ -175,18 +176,12 @@ async def _run_judge_loop(self, sleep_interval: int = 1):
175
176
print ("exiting judge loop" )
176
177
177
178
async def _publish_game_state (self ):
178
- async with aiohttp .ClientSession () as session :
179
- await api .room_service .RoomService (
180
- session ,
181
- os .getenv ("LIVEKIT_URL" ),
182
- os .getenv ("LIVEKIT_API_KEY" ),
183
- os .getenv ("LIVEKIT_API_SECRET" ),
184
- ).update_room_metadata (
185
- protocol .room .UpdateRoomMetadataRequest (
186
- room = self ._ctx .room .name ,
187
- metadata = self ._game_state .to_json_string (),
188
- )
179
+ await self ._lkapi .room .update_room_metadata (
180
+ api .UpdateRoomMetadataRequest (
181
+ room = self ._ctx .room .name ,
182
+ metadata = self ._game_state .to_json_string (),
189
183
)
184
+ )
190
185
191
186
def _register_player (self , participant : rtc .Participant ) -> bool :
192
187
if participant .kind == rtc .ParticipantKind .PARTICIPANT_KIND_AGENT :
@@ -238,17 +233,11 @@ async def _kick_player(self, participant: rtc.Participant, reason: str):
238
233
payload = json .dumps ({"reason" : reason }),
239
234
)
240
235
241
- async with aiohttp .ClientSession () as session :
242
- await api .room_service .RoomService (
243
- session ,
244
- os .getenv ("LIVEKIT_URL" ),
245
- os .getenv ("LIVEKIT_API_KEY" ),
246
- os .getenv ("LIVEKIT_API_SECRET" ),
247
- ).remove_participant (
248
- protocol .room .RoomParticipantIdentity (
249
- room = self ._ctx .room .name , identity = participant .identity
250
- )
236
+ await self ._lkapi .room .remove_participant (
237
+ api .RemoveParticipantRequest (
238
+ room = self ._ctx .room .name , identity = participant .identity
251
239
)
240
+ )
252
241
253
242
def _unregister_player (self , participant : rtc .Participant ):
254
243
if participant .kind == rtc .ParticipantKind .PARTICIPANT_KIND_AGENT :
0 commit comments