From 44c566ebbf4e513bf5966323c4c94082c4eb990f Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Thu, 19 Sep 2024 15:12:44 -0700 Subject: [PATCH 1/3] Implement TransferParticipant in SIP --- cmd/lk/sip.go | 22 ++++++++++++++++++++++ go.mod | 6 +++++- go.sum | 8 ++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cmd/lk/sip.go b/cmd/lk/sip.go index 8e361331..2fcf250c 100644 --- a/cmd/lk/sip.go +++ b/cmd/lk/sip.go @@ -24,6 +24,7 @@ import ( "github.com/livekit/protocol/livekit" lksdk "github.com/livekit/server-sdk-go/v2" "github.com/urfave/cli/v3" + "google.golang.org/protobuf/types/known/emptypb" ) //lint:file-ignore SA1019 we still support older APIs for compatibility @@ -128,6 +129,12 @@ var ( Action: createSIPParticipant, ArgsUsage: RequestDesc[livekit.CreateSIPParticipantRequest](), }, + { + Name: "transfer", + Usage: "Transfer a SIP Participant", + Action: transferSIPParticipant, + ArgsUsage: RequestDesc[livekit.TransferSIPParticipantRequest](), + }, }, }, }, @@ -481,6 +488,21 @@ func createSIPParticipantLegacy(ctx context.Context, cmd *cli.Command) error { }, printSIPParticipantInfo) } +func transferSIPParticipant(ctx context.Context, cmd *cli.Command) error { + cli, err := createSIPClient(cmd) + if err != nil { + return err + } + return createAndPrintReqs(ctx, cmd, func(ctx context.Context, req *livekit.TransferSIPParticipantRequest) (*emptypb.Empty, error) { + // CreateSIPParticipant will wait for LiveKit Participant to be created and that can take some time. + // Default deadline is too short, thus, we must set a higher deadline for it. + ctx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + + return cli.TransferSIPParticipant(ctx, req) + }, func(r *emptypb.Empty) {}) +} + func printSIPParticipantInfo(info *livekit.SIPParticipantInfo) { fmt.Printf("SIPCallID: %v\n", info.SipCallId) fmt.Printf("ParticipantID: %v\n", info.ParticipantId) diff --git a/go.mod b/go.mod index 112b0dc2..6ef2fcfc 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,10 @@ go 1.22 toolchain go1.22.2 +replace github.com/livekit/protocol => ../protocol + +replace github.com/livekit/server-sdk-go/v2 => ../server-sdk-go + require ( github.com/charmbracelet/huh v0.6.0 github.com/charmbracelet/huh/spinner v0.0.0-20240912161303-b56e9290a68e @@ -121,7 +125,7 @@ require ( go.uber.org/zap v1.27.0 // indirect go.uber.org/zap/exp v0.2.0 // indirect golang.org/x/crypto v0.26.0 // indirect - golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.23.0 // indirect diff --git a/go.sum b/go.sum index 8a96969e..79833d3c 100644 --- a/go.sum +++ b/go.sum @@ -130,12 +130,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598 h1:yLlkHk2feSLHstD9n4VKg7YEBR4rLODTI4WE8gNBEnQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE= -github.com/livekit/protocol v1.20.2-0.20240831163355-2454665245fd h1:NeZFjd/4Zb/xxwDdHBbue18wj3+eunBu+BYB3KOKR34= -github.com/livekit/protocol v1.20.2-0.20240831163355-2454665245fd/go.mod h1:AFuwk3+uIWFeO5ohKjx5w606Djl940+wktaZ441VoCI= github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a h1:EQAHmcYEGlc6V517cQ3Iy0+jHgP6+tM/B4l2vGuLpQo= github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0= -github.com/livekit/server-sdk-go/v2 v2.2.1 h1:MK6H52X/k5FA3d613qAawAVvWPwyzxS5CLpxfKd/pD4= -github.com/livekit/server-sdk-go/v2 v2.2.1/go.mod h1:Oqv4EYIqLWjdgWXw8HuxN79QDy77vws1vI9YMkBxSMM= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= @@ -284,8 +280,8 @@ golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1m golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= -golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= From 476e4fcf7a010f6b8fca642906f4cc45e88e7a27 Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Tue, 24 Sep 2024 10:49:00 -0700 Subject: [PATCH 2/3] WiP --- go.mod | 9 ++++----- go.sum | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index fea7f6c2..ad481735 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,9 @@ module github.com/livekit/livekit-cli go 1.22.0 -toolchain go1.22.4 - replace github.com/livekit/protocol => ../protocol -replace github.com/livekit/server-sdk-go/v2 => ../server-sdk-go +toolchain go1.22.4 require ( github.com/charmbracelet/huh v0.6.0 @@ -16,8 +14,8 @@ require ( github.com/go-logr/logr v1.4.2 github.com/go-task/task/v3 v3.39.1 github.com/joho/godotenv v1.5.1 - github.com/livekit/protocol v1.21.1-0.20240919052504-1874ac067983 - github.com/livekit/server-sdk-go/v2 v2.2.1 + github.com/livekit/protocol v1.22.1-0.20240920184753-71b9c184e5c8 + github.com/livekit/server-sdk-go/v2 v2.2.2-0.20240920185319-a83c50186010 github.com/pion/rtcp v1.2.14 github.com/pion/rtp v1.8.9 github.com/pion/webrtc/v3 v3.3.3 @@ -126,6 +124,7 @@ require ( go.uber.org/zap/exp v0.2.0 // indirect golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect + golang.org/x/mod v0.20.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/go.sum b/go.sum index 6f5efc11..5a6d1f34 100644 --- a/go.sum +++ b/go.sum @@ -130,8 +130,12 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598 h1:yLlkHk2feSLHstD9n4VKg7YEBR4rLODTI4WE8gNBEnQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE= +github.com/livekit/protocol v1.22.1-0.20240920184753-71b9c184e5c8 h1:Tt/INVn5HOgyy/OknLzEK46sWDKRnQ+NvsjFkMZDbWc= +github.com/livekit/protocol v1.22.1-0.20240920184753-71b9c184e5c8/go.mod h1:AFuwk3+uIWFeO5ohKjx5w606Djl940+wktaZ441VoCI= github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a h1:EQAHmcYEGlc6V517cQ3Iy0+jHgP6+tM/B4l2vGuLpQo= github.com/livekit/psrpc v0.5.3-0.20240616012458-ac39c8549a0a/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0= +github.com/livekit/server-sdk-go/v2 v2.2.2-0.20240920185319-a83c50186010 h1:skq+yZbTLm2yUIJ2eEyzQR+LYZEOIl9uFNAPJMQXaVs= +github.com/livekit/server-sdk-go/v2 v2.2.2-0.20240920185319-a83c50186010/go.mod h1:LjZPbNnUGUIUeAqjQb2CozRK3yOXc07pLsLyK1VqdoU= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= @@ -284,6 +288,8 @@ golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++ golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= From a15feb843acf828dc8ec0bd3f24c0c1c2fbc8ccd Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Tue, 24 Sep 2024 12:24:08 -0700 Subject: [PATCH 3/3] Review feedback --- cmd/lk/sip.go | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/cmd/lk/sip.go b/cmd/lk/sip.go index 2fcf250c..5d02e2a9 100644 --- a/cmd/lk/sip.go +++ b/cmd/lk/sip.go @@ -24,7 +24,6 @@ import ( "github.com/livekit/protocol/livekit" lksdk "github.com/livekit/server-sdk-go/v2" "github.com/urfave/cli/v3" - "google.golang.org/protobuf/types/known/emptypb" ) //lint:file-ignore SA1019 we still support older APIs for compatibility @@ -130,10 +129,18 @@ var ( ArgsUsage: RequestDesc[livekit.CreateSIPParticipantRequest](), }, { - Name: "transfer", - Usage: "Transfer a SIP Participant", - Action: transferSIPParticipant, - ArgsUsage: RequestDesc[livekit.TransferSIPParticipantRequest](), + Name: "transfer", + Usage: "Transfer a SIP Participant", + Action: transferSIPParticipant, + Flags: []cli.Flag{ + roomFlag, + identityFlag, + &cli.StringFlag{ + Name: "to", + Required: true, + Usage: "`SIP URL` to transfer the call to. Use 'tel:' to transfer to a phone", + }, + }, }, }, }, @@ -489,18 +496,26 @@ func createSIPParticipantLegacy(ctx context.Context, cmd *cli.Command) error { } func transferSIPParticipant(ctx context.Context, cmd *cli.Command) error { + roomName, identity := participantInfoFromArgOrFlags(cmd) + to := cmd.String("to") + + req := livekit.TransferSIPParticipantRequest{ + RoomName: roomName, + ParticipantIdentity: identity, + TransferTo: to, + } + cli, err := createSIPClient(cmd) if err != nil { return err } - return createAndPrintReqs(ctx, cmd, func(ctx context.Context, req *livekit.TransferSIPParticipantRequest) (*emptypb.Empty, error) { - // CreateSIPParticipant will wait for LiveKit Participant to be created and that can take some time. - // Default deadline is too short, thus, we must set a higher deadline for it. - ctx, cancel := context.WithTimeout(ctx, 30*time.Second) - defer cancel() - return cli.TransferSIPParticipant(ctx, req) - }, func(r *emptypb.Empty) {}) + _, err = cli.TransferSIPParticipant(ctx, &req) + if err != nil { + return err + } + + return nil } func printSIPParticipantInfo(info *livekit.SIPParticipantInfo) {