Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TransferParticipant in SIP #425

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions cmd/lk/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:<phone number>' to transfer to a phone",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the tel: prefix a part of SIP spec? Did I miss the parsing part in the REFER PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supported and documented by Twilio. It's unclear if other providers support it as well. We can adjust the documentation as needed.

},
},
},
},
},
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ go 1.22.0

toolchain go1.23.1

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-20240917123815-c9b2c9cdb7b6
Expand All @@ -16,8 +12,8 @@ require (
github.com/go-logr/logr v1.4.2
github.com/go-task/task/v3 v3.39.2
github.com/joho/godotenv v1.5.1
github.com/livekit/protocol v1.22.0
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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down