Skip to content

Commit

Permalink
Update SIP protocol. Pass headers and project ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Sep 9, 2024
1 parent 387e8ff commit 2c45642
Show file tree
Hide file tree
Showing 16 changed files with 2,109 additions and 856 deletions.
1,055 changes: 707 additions & 348 deletions livekit/livekit_sip.pb.go

Large diffs are not rendered by default.

805 changes: 686 additions & 119 deletions livekit/livekit_sip.twirp.go

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions livekit/sip.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package livekit

import (
"errors"
"fmt"
"strings"
)

// ToProto implements DataPacket in Go SDK.
func (p *SipDTMF) ToProto() *DataPacket {
return &DataPacket{
Expand Down Expand Up @@ -94,3 +100,91 @@ func (p *SIPOutboundTrunkInfo) AsTrunkInfo() *SIPTrunkInfo {
OutboundPassword: p.AuthPassword,
}
}

func validateHeaders(headers map[string]string) error {
for k := range headers {
k = strings.ToLower(k)
if !strings.HasPrefix(k, "x-") {
return fmt.Errorf("only X-* headers are allowed: %s", k)
}
}
return nil
}

func (p *SIPTrunkInfo) Validate() error {
if len(p.InboundNumbersRegex) != 0 {
return fmt.Errorf("trunks with InboundNumbersRegex are deprecated")
}
return nil
}

func (p *CreateSIPOutboundTrunkRequest) Validate() error {
if p.Trunk == nil {
return errors.New("missing trunk")
}
if err := p.Trunk.Validate(); err != nil {
return err
}
return nil
}

func (p *CreateSIPInboundTrunkRequest) Validate() error {
if p.Trunk == nil {
return errors.New("missing trunk")
}
if err := p.Trunk.Validate(); err != nil {
return err
}
return nil
}

func (p *SIPInboundTrunkInfo) Validate() error {
if len(p.Numbers) == 0 {
return errors.New("no trunk numbers specified")
}
if err := validateHeaders(p.Headers); err != nil {
return err
}
if err := validateHeaders(p.HeadersToAttributes); err != nil {
return err
}
return nil
}

func (p *SIPOutboundTrunkInfo) Validate() error {
if len(p.Numbers) == 0 {
return errors.New("no trunk numbers specified")
}
if p.Address == "" {
return errors.New("no outbound address specified")
} else if strings.Contains(p.Address, "@") {
return errors.New("trunk address should be a hostname or IP, not SIP URI")
}
if err := validateHeaders(p.Headers); err != nil {
return err
}
if err := validateHeaders(p.HeadersToAttributes); err != nil {
return err
}
return nil
}

func (p *CreateSIPDispatchRuleRequest) Validate() error {
if p.Rule == nil {
return errors.New("missing rule")
}
return nil
}

func (p *CreateSIPParticipantRequest) Validate() error {
if p.SipTrunkId == "" {
return errors.New("missing sip trunk id")
}
if p.SipCallTo == "" {
return errors.New("missing sip callee number")
}
if p.RoomName == "" {
return errors.New("missing room name")
}
return nil
}
28 changes: 28 additions & 0 deletions protobufs/livekit_sip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ service SIP {

rpc CreateSIPInboundTrunk(CreateSIPInboundTrunkRequest) returns (SIPInboundTrunkInfo);
rpc CreateSIPOutboundTrunk(CreateSIPOutboundTrunkRequest) returns (SIPOutboundTrunkInfo);
rpc GetSIPInboundTrunk(GetSIPInboundTrunkRequest) returns (GetSIPInboundTrunkResponse);
rpc GetSIPOutboundTrunk(GetSIPOutboundTrunkRequest) returns (GetSIPOutboundTrunkResponse);
rpc ListSIPInboundTrunk(ListSIPInboundTrunkRequest) returns (ListSIPInboundTrunkResponse);
rpc ListSIPOutboundTrunk(ListSIPOutboundTrunkRequest) returns (ListSIPOutboundTrunkResponse);
rpc DeleteSIPTrunk(DeleteSIPTrunkRequest) returns (SIPTrunkInfo);
Expand Down Expand Up @@ -178,6 +180,11 @@ message SIPInboundTrunkInfo {
// May be empty to have no authentication.
string auth_username = 7;
string auth_password = 8;

// Include these SIP X-* headers in 200 OK responses.
map<string, string> headers = 9;
// Map SIP X-* headers from INVITE to SIP participant attributes.
map<string, string> headers_to_attributes = 10;
}

message CreateSIPOutboundTrunkRequest {
Expand Down Expand Up @@ -206,6 +213,27 @@ message SIPOutboundTrunkInfo {
// May be empty to have no authentication.
string auth_username = 7;
string auth_password = 8;

// Include these SIP X-* headers in INVITE request.
map<string, string> headers = 9;
// Map SIP X-* headers from 200 OK to SIP participant attributes.
map<string, string> headers_to_attributes = 10;
}

message GetSIPInboundTrunkRequest {
string sip_trunk_id = 1;
}

message GetSIPInboundTrunkResponse {
SIPInboundTrunkInfo trunk = 1;
}

message GetSIPOutboundTrunkRequest {
string sip_trunk_id = 1;
}

message GetSIPOutboundTrunkResponse {
SIPOutboundTrunkInfo trunk = 1;
}

message ListSIPTrunkRequest {
Expand Down
16 changes: 14 additions & 2 deletions protobufs/rpc/io.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ message GetSIPTrunkAuthenticationResponse {
bool drop = 3;
// Trunk used to fulfill this request
string sip_trunk_id = 4;
// Used in Cloud only
string project_id = 5;
}

message EvaluateSIPDispatchRulesRequest {
string sip_call_id = 8;
string sip_participant_id = 1 [deprecated=true];
// Trunk from the auth response, if any
string sip_trunk_id = 10;

// What Number is calling
string calling_number = 2;
Expand All @@ -121,7 +125,7 @@ message EvaluateSIPDispatchRulesRequest {
// Usually include provider-specific metadata.
map<string, string> extra_attributes = 9;

// NEXT ID: 10
// NEXT ID: 11
}

message EvaluateSIPDispatchRulesResponse {
Expand Down Expand Up @@ -151,7 +155,15 @@ message EvaluateSIPDispatchRulesResponse {
string sip_trunk_id = 9;
// Dispatch Rule used to fulfill this request
string sip_dispatch_rule_id = 10;
// NEXT ID: 12

// Used in Cloud only
string project_id = 12;

// Include these SIP X-* headers in 200 OK response.
map<string, string> headers = 13;
// Map SIP X-* headers from INVITE to SIP participant attributes.
map<string, string> headers_to_attributes = 14;
// NEXT ID: 15
}

enum SIPDispatchResult {
Expand Down
13 changes: 11 additions & 2 deletions protobufs/rpc/sip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ service SIPInternal {
}

message InternalCreateSIPParticipantRequest {
// Used in Cloud only
string project_id = 18;

string sip_call_id = 13;
// IP that SIP INVITE is sent too
string sip_trunk_id = 19;
// IP or hostname that SIP INVITE is sent too
string address = 2;
// Hostname for the 'From' SIP address in INVITE
string hostname = 20;
livekit.SIPTransport transport = 16;

// Number used to make the call
Expand Down Expand Up @@ -62,7 +68,10 @@ message InternalCreateSIPParticipantRequest {
// Optionally play ringtone in the room as an audible indicator for existing participants
bool play_ringtone = 12;

// NEXT ID: 18
map<string, string> headers = 21;
map<string, string> headers_to_attributes = 22;

// NEXT ID: 23
}

message InternalCreateSIPParticipantResponse {
Expand Down
20 changes: 10 additions & 10 deletions replay/cloud_replay.pb.go

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

2 changes: 1 addition & 1 deletion rpc/agent_dispatch.pb.go

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

Loading

0 comments on commit 2c45642

Please sign in to comment.