Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into benjamin/sip_call_error
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Oct 25, 2024
2 parents 14f926d + 32abc4d commit cab53ec
Show file tree
Hide file tree
Showing 12 changed files with 932 additions and 885 deletions.
335 changes: 173 additions & 162 deletions livekit/livekit_sip.pb.go

Large diffs are not rendered by default.

287 changes: 144 additions & 143 deletions livekit/livekit_sip.twirp.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions protobufs/livekit_sip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ message CreateSIPParticipantRequest {
// Max call duration.
google.protobuf.Duration max_call_duration = 12;

// NEXT ID: 14
// Enable voice isolation for the callee.
bool enable_krisp = 14;
// NEXT ID: 15
}

message SIPParticipantInfo {
Expand All @@ -430,7 +432,7 @@ message TransferSIPParticipantRequest {
string participant_identity = 1;
string room_name = 2;
string transfer_to = 3;

// Optionally play dialtone to the SIP participant as an audible indicator of being transferred
bool play_dialtone = 4;
}
Expand Down
6 changes: 1 addition & 5 deletions protobufs/rpc/io.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option go_package = "github.com/livekit/protocol/rpc";
import "livekit_egress.proto";
import "livekit_ingress.proto";
import "livekit_sip.proto";
import "rpc/sip.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/duration.proto";

Expand Down Expand Up @@ -185,11 +186,6 @@ message UpdateSIPCallStateRequest {
// NEXT ID: 2
}

enum SIPFeature {
NONE = 0;
KRISP_ENABLED = 1;
}

enum SIPDispatchResult {
LEGACY_ACCEPT_OR_PIN = 0; // check request_pin field
ACCEPT = 1;
Expand Down
11 changes: 9 additions & 2 deletions protobufs/rpc/sip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ message InternalCreateSIPParticipantRequest {
map<string, string> headers = 21;
map<string, string> headers_to_attributes = 22;

repeated SIPFeature enabled_features = 25;

// Max time for the callee to answer the call.
google.protobuf.Duration ringing_timeout = 23;
// Max call duration.
google.protobuf.Duration max_call_duration = 24;

// NEXT ID: 25
// NEXT ID: 26
}

message InternalCreateSIPParticipantResponse {
Expand All @@ -99,7 +101,12 @@ message InternalCreateSIPParticipantResponse {
message InternalTransferSIPParticipantRequest {
string sip_call_id = 1;
string transfer_to = 2;

// Optionally play dialtone to the SIP participant as an audible indicator of being transferred
bool play_dialtone = 3;
}

enum SIPFeature {
NONE = 0;
KRISP_ENABLED = 1;
}
611 changes: 282 additions & 329 deletions rpc/io.pb.go

Large diffs are not rendered by default.

180 changes: 89 additions & 91 deletions rpc/io.psrpc.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions rpc/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func NewCreateSIPParticipantRequest(
attrs[livekit.AttrSIPPhoneNumber] = req.SipCallTo
attrs[livekit.AttrSIPTrunkNumber] = outboundNumber
}

var features []SIPFeature
if req.EnableKrisp {
features = append(features, SIPFeature_KRISP_ENABLED)
}

return &InternalCreateSIPParticipantRequest{
ProjectId: projectID,
SipCallId: callID,
Expand All @@ -67,6 +73,7 @@ func NewCreateSIPParticipantRequest(
PlayDialtone: req.PlayRingtone || req.PlayDialtone,
Headers: trunk.Headers,
HeadersToAttributes: trunk.HeadersToAttributes,
EnabledFeatures: features,
RingingTimeout: req.RingingTimeout,
MaxCallDuration: req.MaxCallDuration,
}, nil
Expand Down
233 changes: 149 additions & 84 deletions rpc/sip.pb.go

Large diffs are not rendered by default.

110 changes: 57 additions & 53 deletions rpc/sip.psrpc.go

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

23 changes: 9 additions & 14 deletions utils/guid/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import (
"github.com/livekit/protocol/utils/must"
)

const (
Size = 12
guidScratchSize = Size + 10
)
const Size = 12

const (
RoomPrefix = "RM_"
Expand All @@ -57,7 +54,7 @@ const (

var guidGeneratorPool = sync.Pool{
New: func() any {
return must.Get(newGenerator(guidScratchSize))
return must.Get(newGenerator())
},
}

Expand Down Expand Up @@ -96,19 +93,17 @@ func newB57Index() [256]byte {
}

type guidGenerator struct {
scratch []byte
rng *mrand.ChaCha8
rng *mrand.ChaCha8
}

func newGenerator(scratchSize int) (*guidGenerator, error) {
func newGenerator() (*guidGenerator, error) {
var seed [32]byte
if _, err := rand.Read(seed[:]); err != nil {
return nil, err
}

return &guidGenerator{
scratch: make([]byte, scratchSize),
rng: mrand.NewChaCha8(seed),
rng: mrand.NewChaCha8(seed),
}, nil
}

Expand All @@ -130,10 +125,10 @@ func (g *guidGenerator) readIDChars(b []byte) {
}

func (g *guidGenerator) New(prefix string) string {
s := append(g.scratch[:0], make([]byte, len(prefix)+Size)...)
copy(s, prefix)
g.readIDChars(s[len(prefix):])
return string(s)
b := make([]byte, len(prefix)+Size)
copy(b, prefix)
g.readIDChars(b[len(prefix):])
return unsafe.String(unsafe.SliceData(b), len(b))
}

func guidPrefix[T livekit.Guid]() string {
Expand Down
8 changes: 8 additions & 0 deletions utils/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ import "google.golang.org/protobuf/proto"
func CloneProto[T proto.Message](m T) T {
return proto.Clone(m).(T)
}

func CloneProtoSlice[T proto.Message](ms []T) []T {
cs := make([]T, len(ms))
for i := range ms {
cs[i] = CloneProto(ms[i])
}
return cs
}

0 comments on commit cab53ec

Please sign in to comment.