Skip to content

Commit 1e7c836

Browse files
authored
Support synchronous SIP outbound calls. (#516)
1 parent 3abcd54 commit 1e7c836

File tree

4 files changed

+97
-32
lines changed

4 files changed

+97
-32
lines changed

.nanpa/sip-outbound-sync.kdl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
minor type="added" "Support synchronous SIP outbound calls"

cmd/lk/sip.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ var (
136136
Name: "room",
137137
Usage: "`ROOM_NAME` to place the call to (overrides json config)",
138138
},
139+
&cli.BoolFlag{
140+
Name: "wait",
141+
Usage: "wait for the call to dial (overrides json config)",
142+
},
143+
&cli.DurationFlag{
144+
Name: "timeout",
145+
Usage: "timeout for the call to dial (requires wait flag)",
146+
Value: 80 * time.Second,
147+
},
139148
},
140149
},
141150
{
@@ -523,14 +532,32 @@ func createSIPParticipant(ctx context.Context, cmd *cli.Command) error {
523532
if v := cmd.String("room"); v != "" {
524533
req.RoomName = v
525534
}
535+
if cmd.Bool("wait") {
536+
req.WaitUntilAnswered = true
537+
}
526538
return req.Validate()
527539
}, func(ctx context.Context, req *livekit.CreateSIPParticipantRequest) (*livekit.SIPParticipantInfo, error) {
528540
// CreateSIPParticipant will wait for LiveKit Participant to be created and that can take some time.
529541
// Default deadline is too short, thus, we must set a higher deadline for it.
530-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
542+
timeout := 30 * time.Second
543+
if req.WaitUntilAnswered {
544+
if dt := cmd.Duration("timeout"); dt != 0 {
545+
timeout = dt
546+
}
547+
}
548+
ctx, cancel := context.WithTimeout(ctx, timeout)
531549
defer cancel()
532550

533-
return cli.CreateSIPParticipant(ctx, req)
551+
resp, err := cli.CreateSIPParticipant(ctx, req)
552+
if e := lksdk.SIPStatusFrom(err); e != nil {
553+
msg := e.Status
554+
if msg == "" {
555+
msg = e.Code.ShortName()
556+
}
557+
fmt.Printf("SIPStatusCode: %d\n", e.Code)
558+
fmt.Printf("SIPStatus: %s\n", msg)
559+
}
560+
return resp, err
534561
}, printSIPParticipantInfo)
535562
}
536563

go.mod

+8-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ require (
1212
github.com/go-logr/logr v1.4.2
1313
github.com/go-task/task/v3 v3.41.0
1414
github.com/joho/godotenv v1.5.1
15-
github.com/livekit/protocol v1.32.1
16-
github.com/livekit/server-sdk-go/v2 v2.4.2
15+
github.com/livekit/protocol v1.33.1-0.20250207105756-81a3dfbd2aca
16+
github.com/livekit/server-sdk-go/v2 v2.4.3-0.20250206112024-0e16924f9906
1717
github.com/pion/rtcp v1.2.15
1818
github.com/pion/rtp v1.8.11
1919
github.com/pion/webrtc/v4 v4.0.8
@@ -25,7 +25,7 @@ require (
2525
go.uber.org/atomic v1.11.0
2626
golang.org/x/sync v0.11.0
2727
golang.org/x/time v0.10.0
28-
google.golang.org/protobuf v1.36.4
28+
google.golang.org/protobuf v1.36.5
2929
gopkg.in/yaml.v3 v3.0.1
3030
)
3131

@@ -36,7 +36,7 @@ require (
3636
dario.cat/mergo v1.0.0 // indirect
3737
github.com/Ladicle/tabwriter v1.0.0 // indirect
3838
github.com/Masterminds/semver/v3 v3.3.1 // indirect
39-
github.com/Microsoft/go-winio v0.6.1 // indirect
39+
github.com/Microsoft/go-winio v0.6.2 // indirect
4040
github.com/ProtonMail/go-crypto v1.1.3 // indirect
4141
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
4242
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
@@ -86,7 +86,7 @@ require (
8686
github.com/lithammer/shortuuid/v4 v4.2.0 // indirect
8787
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 // indirect
8888
github.com/livekit/mediatransportutil v0.0.0-20241220010243-a2bdee945564 // indirect
89-
github.com/livekit/psrpc v0.6.1-0.20241018124827-1efff3d113a8 // indirect
89+
github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 // indirect
9090
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
9191
github.com/magefile/mage v1.15.0 // indirect
9292
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -132,15 +132,13 @@ require (
132132
go.uber.org/zap v1.27.0 // indirect
133133
go.uber.org/zap/exp v0.3.0 // indirect
134134
golang.org/x/crypto v0.32.0 // indirect
135-
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
136-
golang.org/x/mod v0.22.0 // indirect
135+
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
137136
golang.org/x/net v0.34.0 // indirect
138-
golang.org/x/sys v0.29.0 // indirect
137+
golang.org/x/sys v0.30.0 // indirect
139138
golang.org/x/term v0.28.0 // indirect
140139
golang.org/x/text v0.21.0 // indirect
141-
golang.org/x/tools v0.29.0 // indirect
142140
google.golang.org/genproto/googleapis/api v0.0.0-20250124145028-65684f501c47 // indirect
143-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 // indirect
141+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect
144142
google.golang.org/grpc v1.70.0 // indirect
145143
gopkg.in/warnings.v0 v0.1.2 // indirect
146144
mvdan.cc/sh/v3 v3.10.0 // indirect

0 commit comments

Comments
 (0)