27 lines
636 B
Python
27 lines
636 B
Python
# backend/main.py
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from livekit import api
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # permite desde cualquier origen
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.get("/token")
|
|
def get_token(room: str, user: str):
|
|
access = api.AccessToken("devkey", "secret")
|
|
grants = api.VideoGrants(
|
|
room_join=True,
|
|
room=room,
|
|
can_publish=True,
|
|
can_subscribe=True,
|
|
)
|
|
access.with_identity(user).with_grants(grants)
|
|
token = access.to_jwt()
|
|
return {"token": token}
|