# integrations/livekit/client.py
from livekit import api
from core.config import settings

_lk_api = None

def get_livekit_api():
    global _lk_api
    if _lk_api is None:
        _lk_api = api.LiveKitAPI(
            settings.LIVEKIT_HOST,
            settings.LIVEKIT_API_KEY,
            settings.LIVEKIT_API_SECRET
        )
    return _lk_api

async def close_livekit_api():
    global _lk_api
    if _lk_api is not None:
        await _lk_api.aclose()
        _lk_api = None