Skip to content

Commit

Permalink
Add SIP API support (#63)
Browse files Browse the repository at this point in the history
This also makes the VideoGrant constructor call within auth_header calls explicit for clarity.
  • Loading branch information
biglittlebigben authored Oct 3, 2024
1 parent 71fb766 commit c44cd2d
Show file tree
Hide file tree
Showing 22 changed files with 319 additions and 41 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ task :proto do
"./protocol/protobufs/livekit_egress.proto",
"./protocol/protobufs/livekit_ingress.proto",
"./protocol/protobufs/livekit_sip.proto",
"./protocol/protobufs/livekit_metrics.proto",
"./protocol/protobufs/livekit_models.proto",
"./protocol/protobufs/livekit_room.proto",
"./protocol/protobufs/livekit_webhook.proto")
Expand Down
1 change: 1 addition & 0 deletions lib/livekit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
require "livekit/room_service_client"
require "livekit/egress_service_client"
require "livekit/ingress_service_client"
require "livekit/sip_service_client"
12 changes: 10 additions & 2 deletions lib/livekit/auth_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
module LiveKit
# Create authenticated headers when keys are provided
module AuthMixin
def auth_header(video_grant)
def auth_header(
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
headers["Authorization"] = "Bearer #{t.to_jwt}"
headers["User-Agent"] = "LiveKit Ruby SDK"
headers
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(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(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(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(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(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(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(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(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(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(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(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(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(ingressAdmin: true),
headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)),
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/livekit/proto/livekit_agent_dispatch_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/livekit/proto/livekit_agent_dispatch_twirp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by protoc-gen-twirp_ruby 1.10.0, DO NOT EDIT.
# Code generated by protoc-gen-twirp_ruby 1.11.0, DO NOT EDIT.
require 'twirp'
require_relative 'livekit_agent_dispatch_pb.rb'

Expand All @@ -9,7 +9,7 @@ class AgentDispatchServiceService < ::Twirp::Service
service 'AgentDispatchService'
rpc :CreateDispatch, CreateAgentDispatchRequest, AgentDispatch, :ruby_method => :create_dispatch
rpc :DeleteDispatch, DeleteAgentDispatchRequest, AgentDispatch, :ruby_method => :delete_dispatch
rpc :ListDispatch, ListAgentDispatchRequesst, ListAgentDispatchResponse, :ruby_method => :list_dispatch
rpc :ListDispatch, ListAgentDispatchRequest, ListAgentDispatchResponse, :ruby_method => :list_dispatch
end

class AgentDispatchServiceClient < ::Twirp::Client
Expand Down
2 changes: 1 addition & 1 deletion lib/livekit/proto/livekit_agent_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/livekit/proto/livekit_agent_twirp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by protoc-gen-twirp_ruby 1.10.0, DO NOT EDIT.
# Code generated by protoc-gen-twirp_ruby 1.11.0, DO NOT EDIT.
require 'twirp'
require_relative 'livekit_agent_pb.rb'

Expand Down
2 changes: 1 addition & 1 deletion lib/livekit/proto/livekit_egress_twirp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by protoc-gen-twirp_ruby 1.10.0, DO NOT EDIT.
# Code generated by protoc-gen-twirp_ruby 1.11.0, DO NOT EDIT.
require 'twirp'
require_relative 'livekit_egress_pb.rb'

Expand Down
2 changes: 1 addition & 1 deletion lib/livekit/proto/livekit_ingress_twirp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code generated by protoc-gen-twirp_ruby 1.10.0, DO NOT EDIT.
# Code generated by protoc-gen-twirp_ruby 1.11.0, DO NOT EDIT.
require 'twirp'
require_relative 'livekit_ingress_pb.rb'

Expand Down
Loading

0 comments on commit c44cd2d

Please sign in to comment.