Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Oct 3, 2024
1 parent a9bdbcb commit 6b7f5ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
6 changes: 4 additions & 2 deletions lib/livekit/auth_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module LiveKit
# Create authenticated headers when keys are provided
module AuthMixin
def auth_header(
video_grant,
video_grant: nil,
sip_grant: nil
)
headers = {}
t = ::LiveKit::AccessToken.new(api_key: @api_key, api_secret: @api_secret)
t.add_grant(video_grant)
if video_grant != nil
t.add_grant(video_grant)
end
if sip_grant != nil
t.add_sip_grant(sip_grant)
end
Expand Down
18 changes: 9 additions & 9 deletions lib/livekit/egress_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def start_room_composite_egress(
self.rpc(
:StartRoomCompositeEgress,
request,
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand All @@ -73,7 +73,7 @@ def start_participant_egress(
self.rpc(
:StartParticipantEgress,
request,
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def start_track_composite_egress(
self.rpc(
:StartTrackCompositeEgress,
request,
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand All @@ -123,7 +123,7 @@ def start_track_egress(
self.rpc(
:StartTrackEgress,
request,
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand Down Expand Up @@ -154,7 +154,7 @@ def start_web_egress(
self.rpc(
:StartWebEgress,
request,
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand All @@ -165,7 +165,7 @@ def update_layout(egress_id, layout)
egress_id: egress_id,
layout: layout,
),
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand All @@ -180,7 +180,7 @@ def update_stream(egress_id,
add_output_urls: add_output_urls,
remove_output_urls: remove_output_urls,
),
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand All @@ -197,15 +197,15 @@ def list_egress(
active: active,
egress_id: egress_id,
),
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

def stop_egress(egress_id)
self.rpc(
:StopEgress,
Proto::StopEgressRequest.new(egress_id: egress_id),
headers: auth_header(VideoGrant.new(roomRecord: true)),
headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/livekit/ingress_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create_ingress(
self.rpc(
:CreateIngress,
request,
headers: auth_header(VideoGrant.new(ingressAdmin: true)),
headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)),
)
end

Expand Down Expand Up @@ -89,7 +89,7 @@ def update_ingress(
self.rpc(
:UpdateIngress,
request,
headers: auth_header(VideoGrant.new(ingressAdmin: true)),
headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)),
)
end

Expand All @@ -106,7 +106,7 @@ def list_ingress(
self.rpc(
:ListIngress,
request,
headers: auth_header(VideoGrant.new(ingressAdmin: true)),
headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)),
)
end

Expand All @@ -117,7 +117,7 @@ def delete_ingress(ingress_id)
self.rpc(
:DeleteIngress,
request,
headers: auth_header(VideoGrant.new(ingressAdmin: true)),
headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)),
)
end
end
Expand Down
22 changes: 11 additions & 11 deletions lib/livekit/room_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,55 @@ def create_room(name,
max_playout_delay: max_playout_delay,
sync_streams: sync_streams
),
headers: auth_header(VideoGrant.new(roomCreate: true)),
headers:auth_header(video_grant: VideoGrant.new(roomCreate: true)),
)
end

def list_rooms(names: nil)
self.rpc(
:ListRooms,
Proto::ListRoomsRequest.new(names: names),
headers: auth_header(VideoGrant.new(roomList: true)),
headers:auth_header(video_grant: VideoGrant.new(roomList: true)),
)
end

def delete_room(room:)
self.rpc(
:DeleteRoom,
Proto::DeleteRoomRequest.new(room: room),
headers: auth_header(VideoGrant.new(roomCreate: true)),
headers:auth_header(video_grant: VideoGrant.new(roomCreate: true)),
)
end

def update_room_metadata(room:, metadata:)
self.rpc(
:UpdateRoomMetadata,
Proto::UpdateRoomMetadataRequest.new(room: room, metadata: metadata),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

def list_participants(room:)
self.rpc(
:ListParticipants,
Proto::ListParticipantsRequest.new(room: room),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

def get_participant(room:, identity:)
self.rpc(
:GetParticipant,
Proto::RoomParticipantIdentity.new(room: room, identity: identity),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

def remove_participant(room:, identity:)
self.rpc(
:RemoveParticipant,
Proto::RoomParticipantIdentity.new(room: room, identity: identity),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

Expand All @@ -100,7 +100,7 @@ def mute_published_track(room:, identity:, track_sid:, muted:)
track_sid: track_sid,
muted: muted,
),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

Expand Down Expand Up @@ -132,7 +132,7 @@ def update_participant(
self.rpc(
:UpdateParticipant,
req,
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

Expand All @@ -145,7 +145,7 @@ def update_subscriptions(room:, identity:, track_sids:, subscribe:)
track_sids: track_sids,
subscribe: subscribe,
),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end

Expand All @@ -162,7 +162,7 @@ def send_data(room:, data:, kind:,
destination_sids: destination_sids,
destination_identities: destination_identities,
),
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)),
headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)),
)
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/livekit/sip_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_sip_inbound_trunk(
self.rpc(
:CreateSIPInboundTrunk,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand Down Expand Up @@ -88,7 +88,7 @@ def create_sip_outbound_trunk(
self.rpc(
:CreateSIPOutboundTrunk,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -97,7 +97,7 @@ def list_sip_inbound_trunk
self.rpc(
:ListSIPInboundTrunk,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -106,7 +106,7 @@ def list_sip_outbound_trunk
self.rpc(
:ListSIPOutboundTrunk,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -117,7 +117,7 @@ def delete_sip_trunk(sip_trunk_id)
self.rpc(
:DeleteSIPTrunk,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -142,7 +142,7 @@ def create_sip_dispatch_rule(
self.rpc(
:CreateSIPDispatchRule,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -151,7 +151,7 @@ def list_sip_dispatch_rule
self.rpc(
:ListSIPDispatchRule,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand All @@ -162,7 +162,7 @@ def delete_sip_dispatch_rule(sip_dispatch_rule_id)
self.rpc(
:DeleteSIPDispatchRule,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)),
headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
)
end

Expand Down Expand Up @@ -191,7 +191,7 @@ def create_sip_participant(
self.rpc(
:CreateSIPParticipant,
request,
headers: auth_header(nil, sip_grant: SIPGrant.new(call: true)),
headers: auth_header(sip_grant: SIPGrant.new(call: true)),
)
end

Expand All @@ -209,7 +209,7 @@ def transfer_sip_participant(
self.rpc(
:TransferSIPParticipant,
request,
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)),
headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)),
)
end
end
Expand Down

0 comments on commit 6b7f5ed

Please sign in to comment.