diff --git a/livekit-api/livekit/api/egress_service.py b/livekit-api/livekit/api/egress_service.py index a875459b..4828cb5f 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, + ) diff --git a/livekit-api/livekit/api/ingress_service.py b/livekit-api/livekit/api/ingress_service.py index abf691ef..8f7cd718 100644 --- a/livekit-api/livekit/api/ingress_service.py +++ b/livekit-api/livekit/api/ingress_service.py @@ -55,3 +55,39 @@ 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..c0d19a9a 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..c21ef184 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..f9d6f970 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,23 @@ 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_code == 200: + return response_class.FromString(resp.content) + else: + # when we have an error, Twirp always encode it in json + error_data = resp.json() + raise TwirpError(error_data["code"], error_data["msg"])