From 3fcf348f3d0bacc4a716c1a5ce0cc6276f771014 Mon Sep 17 00:00:00 2001 From: sjportalatin Date: Tue, 27 Aug 2024 09:13:05 -0700 Subject: [PATCH 1/3] Add sync methods to the api service clients --- livekit-api/livekit/api/egress_service.py | 99 +++++++++++++++++ livekit-api/livekit/api/ingress_service.py | 44 ++++++++ livekit-api/livekit/api/room_service.py | 122 +++++++++++++++++++++ livekit-api/livekit/api/sip_service.py | 121 ++++++++++++++++++++ livekit-api/livekit/api/twirp_client.py | 24 ++++ 5 files changed, 410 insertions(+) diff --git a/livekit-api/livekit/api/egress_service.py b/livekit-api/livekit/api/egress_service.py index a875459b..757cf2df 100644 --- a/livekit-api/livekit/api/egress_service.py +++ b/livekit-api/livekit/api/egress_service.py @@ -110,3 +110,102 @@ async def stop_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) + + def sync_start_room_composite_egress( + self, start: proto_egress.RoomCompositeEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StartRoomCompositeEgress", + start, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_start_web_egress( + self, start: proto_egress.WebEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StartWebEgress", + start, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_start_participant_egress( + self, start: proto_egress.ParticipantEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StartParticipantEgress", + start, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_start_track_composite_egress( + self, start: proto_egress.TrackCompositeEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StartTrackCompositeEgress", + start, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_start_track_egress( + self, start: proto_egress.TrackEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StartTrackEgress", + start, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_update_layout( + self, update: proto_egress.UpdateLayoutRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "UpdateLayout", + update, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_update_stream( + self, update: proto_egress.UpdateStreamRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "UpdateStream", + update, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) + + def sync_list_egress( + self, list: proto_egress.ListEgressRequest + ) -> proto_egress.ListEgressResponse: + return self._client.sync_request( + SVC, + "ListEgress", + list, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.ListEgressResponse, + ) + + def sync_stop_egress( + self, stop: proto_egress.StopEgressRequest + ) -> proto_egress.EgressInfo: + return self._client.sync_request( + SVC, + "StopEgress", + stop, + self._auth_header(VideoGrants(room_record=True)), + proto_egress.EgressInfo, + ) \ No newline at end of file diff --git a/livekit-api/livekit/api/ingress_service.py b/livekit-api/livekit/api/ingress_service.py index abf691ef..dc918350 100644 --- a/livekit-api/livekit/api/ingress_service.py +++ b/livekit-api/livekit/api/ingress_service.py @@ -55,3 +55,47 @@ async def delete_ingress( self._auth_header(VideoGrants(ingress_admin=True)), proto_ingress.IngressInfo, ) + + def sync_create_ingress( + self, create: proto_ingress.CreateIngressRequest + ): + return self._client.sync_request( + SVC, + "CreateIngress", + create, + self._auth_header(VideoGrants(ingress_admin=True)), + proto_ingress.IngressInfo, + ) + + def sync_update_ingress( + self, update: proto_ingress.UpdateIngressRequest + ): + return self._client.sync_request( + SVC, + "UpdateIngress", + update, + self._auth_header(VideoGrants(ingress_admin=True)), + proto_ingress.IngressInfo, + ) + + def sync_list_ingress( + self, list: proto_ingress.ListIngressRequest + ): + return self._client.sync_request( + SVC, + "ListIngress", + list, + self._auth_header(VideoGrants(ingress_admin=True)), + proto_ingress.ListIngressResponse, + ) + + def sync_delete_ingress( + self, delete: proto_ingress.DeleteIngressRequest + ): + return self._client.sync_request( + SVC, + "DeleteIngress", + delete, + self._auth_header(VideoGrants(ingress_admin=True)), + proto_ingress.IngressInfo, + ) diff --git a/livekit-api/livekit/api/room_service.py b/livekit-api/livekit/api/room_service.py index 9c1b197a..fe693ae4 100644 --- a/livekit-api/livekit/api/room_service.py +++ b/livekit-api/livekit/api/room_service.py @@ -134,3 +134,125 @@ async def send_data( self._auth_header(VideoGrants(room_admin=True, room=send.room)), proto_room.SendDataResponse, ) + + def sync_create_room( + self, create: proto_room.CreateRoomRequest + ) -> proto_models.Room: + return self._client.sync_request( + SVC, + "CreateRoom", + create, + self._auth_header(VideoGrants(room_create=True)), + proto_models.Room, + ) + + def sync_delete_room( + self, delete: proto_room.DeleteRoomRequest + ) -> proto_room.DeleteRoomResponse: + return self._client.sync_request( + SVC, + "DeleteRoom", + delete, + self._auth_header(VideoGrants(room_create=True)), + proto_room.DeleteRoomResponse, + ) + + def sync_update_room_metadata( + self, update: proto_room.UpdateRoomMetadataRequest + ) -> proto_models.Room: + return self._client.sync_request( + SVC, + "UpdateRoomMetadata", + update, + self._auth_header(VideoGrants(room_admin=True, room=update.room)), + proto_models.Room, + ) + + def sync_remove_participant( + self, remove: proto_room.RoomParticipantIdentity + ) -> proto_room.RemoveParticipantResponse: + return self._client.sync_request( + SVC, + "RemoveParticipant", + remove, + self._auth_header(VideoGrants(room_admin=True, room=remove.room)), + proto_room.RemoveParticipantResponse, + ) + + def sync_mute_published_track( + self, + update: proto_room.MuteRoomTrackRequest, + ) -> proto_room.MuteRoomTrackResponse: + return self._client.sync_request( + SVC, + "MutePublishedTrack", + update, + self._auth_header(VideoGrants(room_admin=True, room=update.room)), + proto_room.MuteRoomTrackResponse, + ) + + def sync_update_participant( + self, update: proto_room.UpdateParticipantRequest + ) -> proto_models.ParticipantInfo: + return self._client.sync_request( + SVC, + "UpdateParticipant", + update, + self._auth_header(VideoGrants(room_admin=True, room=update.room)), + proto_models.ParticipantInfo, + ) + + def sync_update_subscriptions( + self, update: proto_room.UpdateSubscriptionsRequest + ) -> proto_room.UpdateSubscriptionsResponse: + return self._client.sync_request( + SVC, + "UpdateSubscriptions", + update, + self._auth_header(VideoGrants(room_admin=True, room=update.room)), + proto_room.UpdateSubscriptionsResponse, + ) + + def sync_send_data( + self, send: proto_room.SendDataRequest + ) -> proto_room.SendDataResponse: + return self._client.sync_request( + SVC, + "SendData", + send, + self._auth_header(VideoGrants(room_admin=True, room=send.room)), + proto_room.SendDataResponse, + ) + + def sync_list_participants( + self, list: proto_room.ListParticipantsRequest + ) -> proto_room.ListParticipantsResponse: + return self._client.sync_request( + SVC, + "ListParticipants", + list, + self._auth_header(VideoGrants(room_admin=True, room=list.room)), + proto_room.ListParticipantsResponse, + ) + + def sync_get_participant( + self, get: proto_room.RoomParticipantIdentity + ) -> proto_models.ParticipantInfo: + return self._client.sync_request( + SVC, + "GetParticipant", + get, + self._auth_header(VideoGrants(room_admin=True, room=get.room)), + proto_models.ParticipantInfo, + ) + + def sync_list_rooms( + self, list: proto_room.ListRoomsRequest + ) -> proto_room.ListRoomsResponse: + return self._client.sync_request( + SVC, + "ListRooms", + list, + self._auth_header(VideoGrants(room_list=True)), + proto_room.ListRoomsResponse, + ) diff --git a/livekit-api/livekit/api/sip_service.py b/livekit-api/livekit/api/sip_service.py index 80810528..b4b77ec4 100644 --- a/livekit-api/livekit/api/sip_service.py +++ b/livekit-api/livekit/api/sip_service.py @@ -132,3 +132,124 @@ async def create_sip_participant( self._auth_header(VideoGrants(), sip=SIPGrants(call=True)), proto_sip.SIPParticipantInfo, ) + + def sync_create_sip_trunk( + self, create: proto_sip.CreateSIPTrunkRequest + ) -> proto_sip.SIPTrunkInfo: + return self._client.sync_request( + SVC, + "CreateSIPTrunk", + create, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPTrunkInfo, + ) + + def sync_create_sip_inbound_trunk( + self, create: proto_sip.CreateSIPInboundTrunkRequest + ) -> proto_sip.SIPInboundTrunkInfo: + return self._client.sync_request( + SVC, + "CreateSIPInboundTrunk", + create, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPInboundTrunkInfo, + ) + + def sync_create_sip_outbound_trunk( + self, create: proto_sip.CreateSIPOutboundTrunkRequest + ) -> proto_sip.SIPOutboundTrunkInfo: + return self._client.sync_request( + SVC, + "CreateSIPOutboundTrunk", + create, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPOutboundTrunkInfo, + ) + + def sync_list_sip_trunk( + self, list: proto_sip.ListSIPTrunkRequest + ) -> proto_sip.ListSIPTrunkResponse: + return self._client.sync_request( + SVC, + "ListSIPTrunk", + list, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.ListSIPTrunkResponse, + ) + + def sync_list_sip_inbound_trunk( + self, list: proto_sip.ListSIPInboundTrunkRequest + ) -> proto_sip.ListSIPInboundTrunkResponse: + return self._client.sync_request( + SVC, + "ListSIPInboundTrunk", + list, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.ListSIPInboundTrunkResponse, + ) + + def sync_list_sip_outbound_trunk( + self, list: proto_sip.ListSIPOutboundTrunkRequest + ) -> proto_sip.ListSIPOutboundTrunkResponse: + return self._client.sync_request( + SVC, + "ListSIPOutboundTrunk", + list, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.ListSIPOutboundTrunkResponse, + ) + + def sync_delete_sip_trunk( + self, delete: proto_sip.DeleteSIPTrunkRequest + ) -> proto_sip.SIPTrunkInfo: + return self._client.sync_request( + SVC, + "DeleteSIPTrunk", + delete, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPTrunkInfo, + ) + + def sync_create_sip_dispatch_rule( + self, create: proto_sip.CreateSIPDispatchRuleRequest + ) -> proto_sip.SIPDispatchRuleInfo: + return self._client.sync_request( + SVC, + "CreateSIPDispatchRule", + create, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPDispatchRuleInfo, + ) + + def sync_list_sip_dispatch_rule( + self, list: proto_sip.ListSIPDispatchRuleRequest + ) -> proto_sip.ListSIPDispatchRuleResponse: + return self._client.sync_request( + SVC, + "ListSIPDispatchRule", + list, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.ListSIPDispatchRuleResponse, + ) + + def sync_delete_sip_dispatch_rule( + self, delete: proto_sip.DeleteSIPDispatchRuleRequest + ) -> proto_sip.SIPDispatchRuleInfo: + return self._client.sync_request( + SVC, + "DeleteSIPDispatchRule", + delete, + self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), + proto_sip.SIPDispatchRuleInfo, + ) + + def sync_create_sip_participant( + self, create: proto_sip.CreateSIPParticipantRequest + ) -> proto_sip.SIPParticipantInfo: + return self._client.sync_request( + SVC, + "CreateSIPParticipant", + create, + self._auth_header(VideoGrants(), sip=SIPGrants(call=True)), + proto_sip.SIPParticipantInfo, + ) diff --git a/livekit-api/livekit/api/twirp_client.py b/livekit-api/livekit/api/twirp_client.py index 1c930270..ffb7eb2b 100644 --- a/livekit-api/livekit/api/twirp_client.py +++ b/livekit-api/livekit/api/twirp_client.py @@ -18,6 +18,8 @@ from google.protobuf.message import Message from urllib.parse import urlparse +import requests + DEFAULT_PREFIX = "twirp" @@ -99,3 +101,25 @@ async def request( # when we have an error, Twirp always encode it in json error_data = await resp.json() raise TwirpError(error_data["code"], error_data["msg"]) + + def sync_request( + self, + service: str, + method: str, + data: Message, + headers: Dict[str, str], + response_class: Type[T], + ) -> T: + url = f"{self.host}/{self.prefix}/{self.pkg}.{service}/{method}" + headers["Content-Type"] = "application/protobuf" + + serialized_data = data.SerializeToString() + resp = requests.post( + url, headers=headers, data=serialized_data + ) + if resp.status == 200: + return response_class.FromString(resp.data()) + else: + # when we have an error, Twirp always encode it in json + error_data = resp.json() + raise TwirpError(error_data["code"], error_data["msg"]) \ No newline at end of file From 84cff3f2ac910f779f817d4593ca5596715ac0fe Mon Sep 17 00:00:00 2001 From: sjportalatin Date: Tue, 27 Aug 2024 09:14:56 -0700 Subject: [PATCH 2/3] Run linter --- livekit-api/livekit/api/egress_service.py | 18 +++++++++--------- livekit-api/livekit/api/ingress_service.py | 22 +++++++--------------- livekit-api/livekit/api/room_service.py | 20 ++++++++++---------- livekit-api/livekit/api/sip_service.py | 20 ++++++++++---------- livekit-api/livekit/api/twirp_client.py | 8 +++----- 5 files changed, 39 insertions(+), 49 deletions(-) diff --git a/livekit-api/livekit/api/egress_service.py b/livekit-api/livekit/api/egress_service.py index 757cf2df..4828cb5f 100644 --- a/livekit-api/livekit/api/egress_service.py +++ b/livekit-api/livekit/api/egress_service.py @@ -121,7 +121,7 @@ def sync_start_room_composite_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_start_web_egress( self, start: proto_egress.WebEgressRequest ) -> proto_egress.EgressInfo: @@ -132,7 +132,7 @@ def sync_start_web_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_start_participant_egress( self, start: proto_egress.ParticipantEgressRequest ) -> proto_egress.EgressInfo: @@ -143,7 +143,7 @@ def sync_start_participant_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_start_track_composite_egress( self, start: proto_egress.TrackCompositeEgressRequest ) -> proto_egress.EgressInfo: @@ -154,7 +154,7 @@ def sync_start_track_composite_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_start_track_egress( self, start: proto_egress.TrackEgressRequest ) -> proto_egress.EgressInfo: @@ -165,7 +165,7 @@ def sync_start_track_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_update_layout( self, update: proto_egress.UpdateLayoutRequest ) -> proto_egress.EgressInfo: @@ -176,7 +176,7 @@ def sync_update_layout( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_update_stream( self, update: proto_egress.UpdateStreamRequest ) -> proto_egress.EgressInfo: @@ -187,7 +187,7 @@ def sync_update_stream( self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, ) - + def sync_list_egress( self, list: proto_egress.ListEgressRequest ) -> proto_egress.ListEgressResponse: @@ -198,7 +198,7 @@ def sync_list_egress( self._auth_header(VideoGrants(room_record=True)), proto_egress.ListEgressResponse, ) - + def sync_stop_egress( self, stop: proto_egress.StopEgressRequest ) -> proto_egress.EgressInfo: @@ -208,4 +208,4 @@ def sync_stop_egress( stop, self._auth_header(VideoGrants(room_record=True)), proto_egress.EgressInfo, - ) \ No newline at end of file + ) diff --git a/livekit-api/livekit/api/ingress_service.py b/livekit-api/livekit/api/ingress_service.py index dc918350..8f7cd718 100644 --- a/livekit-api/livekit/api/ingress_service.py +++ b/livekit-api/livekit/api/ingress_service.py @@ -56,9 +56,7 @@ async def delete_ingress( proto_ingress.IngressInfo, ) - def sync_create_ingress( - self, create: proto_ingress.CreateIngressRequest - ): + def sync_create_ingress(self, create: proto_ingress.CreateIngressRequest): return self._client.sync_request( SVC, "CreateIngress", @@ -66,10 +64,8 @@ def sync_create_ingress( self._auth_header(VideoGrants(ingress_admin=True)), proto_ingress.IngressInfo, ) - - def sync_update_ingress( - self, update: proto_ingress.UpdateIngressRequest - ): + + def sync_update_ingress(self, update: proto_ingress.UpdateIngressRequest): return self._client.sync_request( SVC, "UpdateIngress", @@ -77,10 +73,8 @@ def sync_update_ingress( self._auth_header(VideoGrants(ingress_admin=True)), proto_ingress.IngressInfo, ) - - def sync_list_ingress( - self, list: proto_ingress.ListIngressRequest - ): + + def sync_list_ingress(self, list: proto_ingress.ListIngressRequest): return self._client.sync_request( SVC, "ListIngress", @@ -88,10 +82,8 @@ def sync_list_ingress( self._auth_header(VideoGrants(ingress_admin=True)), proto_ingress.ListIngressResponse, ) - - def sync_delete_ingress( - self, delete: proto_ingress.DeleteIngressRequest - ): + + def sync_delete_ingress(self, delete: proto_ingress.DeleteIngressRequest): return self._client.sync_request( SVC, "DeleteIngress", diff --git a/livekit-api/livekit/api/room_service.py b/livekit-api/livekit/api/room_service.py index fe693ae4..c0d19a9a 100644 --- a/livekit-api/livekit/api/room_service.py +++ b/livekit-api/livekit/api/room_service.py @@ -145,7 +145,7 @@ def sync_create_room( self._auth_header(VideoGrants(room_create=True)), proto_models.Room, ) - + def sync_delete_room( self, delete: proto_room.DeleteRoomRequest ) -> proto_room.DeleteRoomResponse: @@ -156,7 +156,7 @@ def sync_delete_room( self._auth_header(VideoGrants(room_create=True)), proto_room.DeleteRoomResponse, ) - + def sync_update_room_metadata( self, update: proto_room.UpdateRoomMetadataRequest ) -> proto_models.Room: @@ -167,7 +167,7 @@ def sync_update_room_metadata( self._auth_header(VideoGrants(room_admin=True, room=update.room)), proto_models.Room, ) - + def sync_remove_participant( self, remove: proto_room.RoomParticipantIdentity ) -> proto_room.RemoveParticipantResponse: @@ -178,7 +178,7 @@ def sync_remove_participant( self._auth_header(VideoGrants(room_admin=True, room=remove.room)), proto_room.RemoveParticipantResponse, ) - + def sync_mute_published_track( self, update: proto_room.MuteRoomTrackRequest, @@ -190,7 +190,7 @@ def sync_mute_published_track( self._auth_header(VideoGrants(room_admin=True, room=update.room)), proto_room.MuteRoomTrackResponse, ) - + def sync_update_participant( self, update: proto_room.UpdateParticipantRequest ) -> proto_models.ParticipantInfo: @@ -201,7 +201,7 @@ def sync_update_participant( self._auth_header(VideoGrants(room_admin=True, room=update.room)), proto_models.ParticipantInfo, ) - + def sync_update_subscriptions( self, update: proto_room.UpdateSubscriptionsRequest ) -> proto_room.UpdateSubscriptionsResponse: @@ -212,7 +212,7 @@ def sync_update_subscriptions( self._auth_header(VideoGrants(room_admin=True, room=update.room)), proto_room.UpdateSubscriptionsResponse, ) - + def sync_send_data( self, send: proto_room.SendDataRequest ) -> proto_room.SendDataResponse: @@ -223,7 +223,7 @@ def sync_send_data( self._auth_header(VideoGrants(room_admin=True, room=send.room)), proto_room.SendDataResponse, ) - + def sync_list_participants( self, list: proto_room.ListParticipantsRequest ) -> proto_room.ListParticipantsResponse: @@ -234,7 +234,7 @@ def sync_list_participants( self._auth_header(VideoGrants(room_admin=True, room=list.room)), proto_room.ListParticipantsResponse, ) - + def sync_get_participant( self, get: proto_room.RoomParticipantIdentity ) -> proto_models.ParticipantInfo: @@ -245,7 +245,7 @@ def sync_get_participant( self._auth_header(VideoGrants(room_admin=True, room=get.room)), proto_models.ParticipantInfo, ) - + def sync_list_rooms( self, list: proto_room.ListRoomsRequest ) -> proto_room.ListRoomsResponse: diff --git a/livekit-api/livekit/api/sip_service.py b/livekit-api/livekit/api/sip_service.py index b4b77ec4..c21ef184 100644 --- a/livekit-api/livekit/api/sip_service.py +++ b/livekit-api/livekit/api/sip_service.py @@ -143,7 +143,7 @@ def sync_create_sip_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPTrunkInfo, ) - + def sync_create_sip_inbound_trunk( self, create: proto_sip.CreateSIPInboundTrunkRequest ) -> proto_sip.SIPInboundTrunkInfo: @@ -154,7 +154,7 @@ def sync_create_sip_inbound_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPInboundTrunkInfo, ) - + def sync_create_sip_outbound_trunk( self, create: proto_sip.CreateSIPOutboundTrunkRequest ) -> proto_sip.SIPOutboundTrunkInfo: @@ -165,7 +165,7 @@ def sync_create_sip_outbound_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPOutboundTrunkInfo, ) - + def sync_list_sip_trunk( self, list: proto_sip.ListSIPTrunkRequest ) -> proto_sip.ListSIPTrunkResponse: @@ -176,7 +176,7 @@ def sync_list_sip_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.ListSIPTrunkResponse, ) - + def sync_list_sip_inbound_trunk( self, list: proto_sip.ListSIPInboundTrunkRequest ) -> proto_sip.ListSIPInboundTrunkResponse: @@ -187,7 +187,7 @@ def sync_list_sip_inbound_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.ListSIPInboundTrunkResponse, ) - + def sync_list_sip_outbound_trunk( self, list: proto_sip.ListSIPOutboundTrunkRequest ) -> proto_sip.ListSIPOutboundTrunkResponse: @@ -198,7 +198,7 @@ def sync_list_sip_outbound_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.ListSIPOutboundTrunkResponse, ) - + def sync_delete_sip_trunk( self, delete: proto_sip.DeleteSIPTrunkRequest ) -> proto_sip.SIPTrunkInfo: @@ -209,7 +209,7 @@ def sync_delete_sip_trunk( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPTrunkInfo, ) - + def sync_create_sip_dispatch_rule( self, create: proto_sip.CreateSIPDispatchRuleRequest ) -> proto_sip.SIPDispatchRuleInfo: @@ -220,7 +220,7 @@ def sync_create_sip_dispatch_rule( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPDispatchRuleInfo, ) - + def sync_list_sip_dispatch_rule( self, list: proto_sip.ListSIPDispatchRuleRequest ) -> proto_sip.ListSIPDispatchRuleResponse: @@ -231,7 +231,7 @@ def sync_list_sip_dispatch_rule( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.ListSIPDispatchRuleResponse, ) - + def sync_delete_sip_dispatch_rule( self, delete: proto_sip.DeleteSIPDispatchRuleRequest ) -> proto_sip.SIPDispatchRuleInfo: @@ -242,7 +242,7 @@ def sync_delete_sip_dispatch_rule( self._auth_header(VideoGrants(), sip=SIPGrants(admin=True)), proto_sip.SIPDispatchRuleInfo, ) - + def sync_create_sip_participant( self, create: proto_sip.CreateSIPParticipantRequest ) -> proto_sip.SIPParticipantInfo: diff --git a/livekit-api/livekit/api/twirp_client.py b/livekit-api/livekit/api/twirp_client.py index ffb7eb2b..ce5008a4 100644 --- a/livekit-api/livekit/api/twirp_client.py +++ b/livekit-api/livekit/api/twirp_client.py @@ -101,7 +101,7 @@ async def request( # when we have an error, Twirp always encode it in json error_data = await resp.json() raise TwirpError(error_data["code"], error_data["msg"]) - + def sync_request( self, service: str, @@ -114,12 +114,10 @@ def sync_request( headers["Content-Type"] = "application/protobuf" serialized_data = data.SerializeToString() - resp = requests.post( - url, headers=headers, data=serialized_data - ) + resp = requests.post(url, headers=headers, data=serialized_data) if resp.status == 200: return response_class.FromString(resp.data()) else: # when we have an error, Twirp always encode it in json error_data = resp.json() - raise TwirpError(error_data["code"], error_data["msg"]) \ No newline at end of file + raise TwirpError(error_data["code"], error_data["msg"]) From 6efb84b3750d8b7d0c2b9a40548b88d815e2d326 Mon Sep 17 00:00:00 2001 From: sjportalatin <158090554+sjportalatin@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:22:45 -0700 Subject: [PATCH 3/3] Correct usage is .content for bytes, not .data() --- livekit-api/livekit/api/twirp_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/livekit-api/livekit/api/twirp_client.py b/livekit-api/livekit/api/twirp_client.py index ce5008a4..f9d6f970 100644 --- a/livekit-api/livekit/api/twirp_client.py +++ b/livekit-api/livekit/api/twirp_client.py @@ -115,8 +115,8 @@ def sync_request( serialized_data = data.SerializeToString() resp = requests.post(url, headers=headers, data=serialized_data) - if resp.status == 200: - return response_class.FromString(resp.data()) + if resp.status_code == 200: + return response_class.FromString(resp.content) else: # when we have an error, Twirp always encode it in json error_data = resp.json()