File tree Expand file tree Collapse file tree 3 files changed +48
-8
lines changed Expand file tree Collapse file tree 3 files changed +48
-8
lines changed Original file line number Diff line number Diff line change 1+ from livekit import api
2+ import asyncio
3+
4+
5+ async def main ():
6+ # will automatically use the LIVEKIT_API_KEY and LIVEKIT_API_SECRET env vars
7+ lkapi = api .LiveKitAPI ("http://localhost:7880" )
8+ room_info = await lkapi .room .create_room (
9+ api .CreateRoomRequest (name = "my-room" ),
10+ )
11+ print (room_info )
12+ room_list = await lkapi .room .list_rooms (api .ListRoomsRequest ())
13+ print (room_list )
14+ await lkapi .aclose ()
15+
16+
17+ if __name__ == "__main__" :
18+ asyncio .get_event_loop ().run_until_complete (main ())
Original file line number Diff line number Diff line change 1+ from livekit import api
2+ from aiohttp import web
3+
4+
5+ async def handle_webhook (request ):
6+ token_verifier = api .TokenVerifier ()
7+ webhook_receiver = api .WebhookReceiver (token_verifier )
8+
9+ auth_token = request .headers .get ("Authorization" )
10+ if not auth_token :
11+ return web .Response (status = 401 )
12+
13+ body = await request .read ()
14+ event = webhook_receiver .receive (body .decode ("utf-8" ), auth_token )
15+ print ("received event:" , event )
16+
17+ return web .Response (status = 200 )
18+
19+
20+ if __name__ == "__main__" :
21+ app = web .Application ()
22+ app .router .add_post ("/" , handle_webhook )
23+ web .run_app (app , port = 3000 )
Original file line number Diff line number Diff line change @@ -155,21 +155,20 @@ def verify(self, token: str) -> Claims:
155155 leeway = self ._leeway .total_seconds (),
156156 )
157157
158- video_dict = {camel_to_snake (k ): v for k , v in claims ["video" ].items ()}
158+ video_dict = claims .get ("video" , dict ())
159+ video_dict = {camel_to_snake (k ): v for k , v in video_dict .items ()}
159160 video_dict = {
160161 k : v for k , v in video_dict .items () if k in VideoGrants .__dataclass_fields__
161162 }
162163 video = VideoGrants (** video_dict )
163164
164- c = Claims (
165- identity = claims [ "sub" ] ,
166- name = claims [ "name" ] ,
165+ return Claims (
166+ identity = claims . get ( "sub" , "" ) ,
167+ name = claims . get ( "name" , "" ) ,
167168 video = video ,
168- metadata = claims [ "metadata" ] ,
169- sha256 = claims [ "sha256" ] ,
169+ metadata = claims . get ( "metadata" , "" ) ,
170+ sha256 = claims . get ( "sha256" , "" ) ,
170171 )
171- c .identity = claims ["sub" ]
172- return c
173172
174173
175174def camel_to_snake (t : str ):
You can’t perform that action at this time.
0 commit comments